硒刮:更改时区 [英] Selenium scraping: changing timezone

查看:104
本文介绍了硒刮:更改时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Selenium运行无头(PhantomJS)浏览器的网站所处的时区不同,因此我为许多条目输入了错误的日期.因此,我的抓取结果显示了错误的日期/时间(我在美国东部标准时间,看起来网站默认为格林尼治标准时间).

The website I run my headless (PhantomJS) browser through Selenium has different timezone so I get the wrong dates for many entries. Thus my scraped results show the wrong dates/times (i'm in EST, looks like website default is GMT).

我正在从网站抓取.您可以在此处上的上一个问题来了解我如何抓取日期>.请注意,但是我目前还没有抓紧时间进行游戏,所以我不想将其纳入解决方案中.

I'm scraping from this website. You can get an idea of how i'm scraping dates through a previous question on SO here. Note however i'm not currently scraping the times of games so i'd prefer not to incorporate this in a solution.

问相同的问题 ,但是我不知道如何测试检查网站默认时间的显而易见"解决方案.我想有人会要求客户提供时间并从当前时间中增加/减去小时吗?有人可以告诉我该怎么做和/或是否有更好的方法.

The same question is asked here but I don't know how to test the 'obvious' solution of checking to see what time the website is defaulting to. I suppose one would request a time from the client and add/subtract hours from my current time? Can someone please tell me how to do that and/or if there's a better way.

我想要的是将网站抓取的数据从默认(GMT)更改为我的时间(EST).这样可以避免增加时间.日期将反映出它们对我的意义.

what I want is to change the website scraped data from the default (GMT) to my time (EST). This will avoid having to mess with adding hours; the dates will reflect what they are for me.

据我所知:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
#from selenium.webdriver.support.select import Select

driver = webdriver.PhantomJS(executable_path=r'C:/phantomjs.exe')
driver.get('http://www.oddsportal.com/hockey/usa/nhl/results/')

zoneDropDownID = "timezone-content"

driver.implicitly_wait(5)
zoneDropDownElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(zoneDropDownID))
# Select(zoneDropDownID).select_by_visible_text("Eastern") # strobject has no attribute
test = zoneDropDownID.select_by_visible_text("Eastern").click() # TimeOut exception - not found

driver.close()

但是我无法点击它.我应该改为搜索课程吗?

But I can't get it to click. Should I be searching for a class instead?

推荐答案

只需转到该网址:

driver.get('http://www.oddsportal.com/set-timezone/15/')

这篇关于硒刮:更改时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆