Selenium scraping: changing timezone

The website where I run a headerless browser (PhantomJS) via Selenium has a different time zone, so I am getting wrong dates for many entries. So my cleaned results show wrong dates / times (I'm in EST, it looks like the default site is GMT).

I am scraping this site. You can get an idea of ​​how I am scraping dates from a previous SO question here . Note, however, I am not currently clearing game times, so I would rather not include this in the solution.

The same question is asked here , but I don't know how to test the "obvious" solution for checking what time the website is down. I'm guessing someone will ask the client for the time and add / subtract hours from my current time? Can someone please tell me how to do this and / or if there is a better way.

Edit: what I want is to change the data of the scrapers on the website from the default (GMT) to my time (EST). This will avoid problems with adding hours; dates will reflect what they are to me.

Here's how I understood it:

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 looking for a class instead?

+2


source to share


2 answers


Just go to this url:



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

      

+1


source


The best idea for testing is using chrome plating or something similar. The advantage is that you can visually check what your script is doing. Here is some sample code (no errohandling) that does what you want. Please note, chromedriver.exe must be in the same location as the script.



from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--lang=en")
chrome = webdriver.Chrome(chrome_options=chrome_options)
wait = WebDriverWait(chrome, 300)

import time

chrome.get("http://www.oddsportal.com/hockey/usa/nhl/results/")

dropdown = wait.until(EC.presence_of_element_located((By.ID,"user-header-timezone-expander")))
dropdown.click()

userHeader = chrome.find_element_by_id('user-header-timezone')
time.sleep(2)
ahref = userHeader.find_elements_by_tag_name('a')

for a in ahref:
    print(a.get_attribute("text"))
    if "Eastern Time" in a.get_attribute('text'):
        a.click()
time.sleep(10)
chrome.close()

      

+3


source







All Articles