1

I've been trying to parse the links ended with 20012019.csv from a webpage using the below script but the thing is I'm always having timeout exception error. It occurred to me that I did things in the right way.

However, any insight as to where I'm going wrong will be highly appreciated.

My attempt so far:

from selenium import webdriver

url = 'https://promo.betfair.com/betfairsp/prices'

def get_info(driver,link):
    driver.get(link)
    for item in driver.find_elements_by_css_selector("a[href$='20012019.csv']"):
        print(item.get_attribute("href"))

if __name__ == '__main__':
    driver = webdriver.Chrome()
    try:
        get_info(driver,url)
    finally:
        driver.quit()
4
  • 1
    it worked without error for me, try time.sleep() Commented Jan 20, 2019 at 17:52
  • 2
    Selenium is overkill for this project. Have you considered using requests and BeautifulSoup? Commented Jan 20, 2019 at 18:05
  • The content are dynamic so I highly doubt requests can handle them @nicholishen. Commented Jan 21, 2019 at 4:20
  • 1
    It's not dynamic, it streams a very large html file Commented Jan 21, 2019 at 4:24

2 Answers 2

2

Your code is fine (tried it and it works), the reason you get a timeout is because the default timeout is 60s according to this answer and the page is huge.

Add this to your code before making the get request (to wait 180s before timeout):

driver.set_page_load_timeout(180)
Sign up to request clarification or add additional context in comments.

Comments

0

You were close. You have to induce WebDriverWait for the the visibility of all elements located and you need to change the line:

for item in driver.find_elements_by_css_selector("a[href$='20012019.csv']"):

to:

for item in WebDriverWait(driver, 30).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "a[href$='20012019.csv']"))):

Note : You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.