Created
May 23, 2021 16:33
-
-
Save isaacharrisholt/4ecfdf96aeffdd672b70ca170ef03c3e to your computer and use it in GitHub Desktop.
Partial code for web scraping Betfair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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