Skip to content

Instantly share code, notes, and snippets.

@isaacharrisholt
Created May 23, 2021 16:33
Show Gist options
  • Save isaacharrisholt/4ecfdf96aeffdd672b70ca170ef03c3e to your computer and use it in GitHub Desktop.
Save isaacharrisholt/4ecfdf96aeffdd672b70ca170ef03c3e to your computer and use it in GitHub Desktop.
Partial code for web scraping Betfair
# Main function
def get_data(queue, sport, markets=None):
if markets is None:
markets = []
# Initialise the webdriver
driver = initialise_webdriver()
# Open page and accept cookies
driver.get(SITE_LINK)
accept_cookies(driver)
# Select relevant sport from list and return availability
sport_available = select_sport(driver, sport)
# If sport not available, log message and return empty dictionary
if not sport_available:
print(f'- Betfair: No live {sport.lower()} available right now.')
queue.put({})
return
# Get all the odds
try:
odds_dict = get_all_odds(driver, markets)
except TimeoutError:
print(f'- Betfair: Timed out, returning.')
queue.put({})
return
# Finished with the driver. It can sleep now
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment