Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium XPATH
#1
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:
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 !
Reply


Messages In This Thread
Selenium XPATH - by jimsxxl - Apr-05-2021, 05:23 PM
RE: Selenium XPATH - by Larz60+ - Apr-06-2021, 01:15 AM
RE: Selenium XPATH - by jimsxxl - Apr-06-2021, 03:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  need help with xpath pythonprogrammer 1 2,772 Jan-18-2020, 11:28 PM
Last Post: snippsat
  Selenium xpath finding gif to click fyec 1 3,815 Jul-27-2018, 05:20 PM
Last Post: snippsat
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,644 Nov-03-2017, 08:41 PM
Last Post: metulburr
  [Selenium] Xpath Drop Down Use Variable digitalmatic7 3 4,418 Oct-07-2017, 01:45 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020