Issue
I'm trying to scrape the data in the expanded container "resulted".
My code below only works when I manually scroll my mouse. If I don't touch my mouse, the container does not expand and I can't scrape the text.
Please give me direction as to how I can expand the container without manually scrolling my mouse wheel.
My code below
target_url = "https://www.racenet.com.au/form-guide/horse-racing/the-valley-20231006/breast-cancer-network-australia-handicap-race-5/overview"
driver.get(target_url)
driver.maximize_window()
driver.execute_script("window.scrollTo(0, 220)")
WebDriverWait(driver,30).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'event-header')))
element = driver.find_element(By.CLASS_NAME, value= 'event-header')
element.click()
WebDriverWait(driver,10)
Solution
It doesn't expand because selenium doesn't wait until the element on view in this case you can use sleep
from time
module.
from time import sleep
# rest of the imports
target_url = "https://www.racenet.com.au/form-guide/horse-racing/the-valley-20231006/breast-cancer-network-australia-handicap-race-5/overview"
driver.get(target_url)
driver.maximize_window()
driver.execute_script("window.scrollTo(0, 220)")
sleep(1)
WebDriverWait(driver,30).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'event-header')))
element = driver.find_element(By.CLASS_NAME, value= 'event-header')
element.click()
# rest of the code
Answered By - Bibhav
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.