Apr-05-2021, 05:23 PM
Hi guys,
Im a beginner when it comes to Python, and wanted to try code a scraper.
Im trying to scrape betfair.com for Team-names and Odds.
I successfully extracted the Team-names, but having abit of trouble getting the odds.
Here is my code:
How can i only get the Odds outputted ?
As i said in the beginning, im totally new to Python, so any comments on how i could improve this code is much appreciated as im still learning !
Thank you in advance !
Im a beginner when it comes to Python, and wanted to try code a scraper.
Im trying to scrape betfair.com for Team-names and Odds.
I successfully extracted the Team-names, but having abit of trouble getting the odds.
Here is my code:
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 import time # Site URL web = 'https://www.betfair.se/exchange/plus/sv/fotboll-betting-1/today' # chrome driver path path = '/usr/bin/chromedriver' # Load site with URL driver = webdriver.Chrome(path) driver.get(web) # Sleep/wait for site to load time.sleep(15) # Find the 'allow-cookies'-button, click it accept = driver.find_element_by_xpath('//*[@id="onetrust-accept-btn-handler"]') accept.click() #sport_title = driver.find_element_by_xpath('//*[@id="main-wrapper"]/div/div[2]/div/ui-view/ui-view/div/div/div/div/div[1]/div/div[1]/bf-super-coupon/main/ng-include[1]/header/h2').text # Get match-table match = WebDriverWait(driver, 600).until(EC.presence_of_all_elements_located((By.XPATH, '//*[@id="main-wrapper"]//ul[@class="runners"]/li'))) # Get odds-table one = WebDriverWait(driver, 600).until(EC.presence_of_all_elements_located((By.XPATH, '//*[@id="main-wrapper"]//div[@class="coupon-runner ng-scope"]/button'))) # Loop them and print output for teams in match: print(teams.text) for odds in one: print(odds.text) # Quit chromedriver driver.quit()The output i get is:
$ python /home/jims/projects/jims-betfair_scraper/jims-betfair_scraper.py Sheffield Wednesday Cardiff Everton Crystal Palace Wolves ... ... ... ... 1.04 303606 kr 1.05 298037 kr 26 3950 kr 28 425 kr ... ... ...As you can see i also getting the "volume"/money extracted along with the odds.
How can i only get the Odds outputted ?
As i said in the beginning, im totally new to Python, so any comments on how i could improve this code is much appreciated as im still learning !
Thank you in advance !