'python selenium scraping a betting site

I recently started coding a program with python selenium. The goal of the project is to calculate arbitrage possibilitys between two sport bookies (but that doesn't really matter here) So I started scraping a website (Bwin) But soon I bumped into a roadblock

enter image description here

As you can see in the photo I want to scrape all the teams + all the kind of bets But some odds are empty/have a lock so I want to replace those with zero

I was possible to scrape all the teams/kinds of odds with the xpath/class

The code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
import pandas as pd
import time
import pickle
import re
import unittest

options = Options()
options.headless = False
web = 'https://sports.bwin.be/nl/sports/live/voetbal-4?fallback=false'
path = r'C:\Users\Senne\Desktop\Chromedriver\chromedriver.exe'

driver = webdriver.Chrome(path, options=options)
driver.get(web)

Cookies = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="onetrust-accept-btn-handler"]')))
Cookies.click()

teams = []
odds = []
x12 = []
btts = []
over_under = []

for event_idx, event_wrapper in enumerate(driver.find_elements(By.CLASS_NAME, "grid-event-wrapper")):
    participants = event_wrapper.find_elements(By.CLASS_NAME, "participant")
    for participant_idx, participant in enumerate(participants):
        print(f"{participant_idx + 1}: {participant.text}")

x12 = driver.find_elements_by_xpath('//*[@id="main-view"]/ms-live/ms-live-event-list/div/ms-grid/ms-event-group/ms-event/div/div/ms-option-group[1]')
for oddx12 in x12:
    print(f"oddx12")
    print(oddx12.text)

MM = driver.find_elements_by_xpath('//*[@id="main-view"]/ms-live/ms-live-event-list/div/ms-grid/ms-event-group/ms-event/div/div/ms-option-group[2]')
for oddMM in MM:
    print(f"oddMM")
    print(oddMM.text)

H01 = driver.find_elements_by_xpath('//*[@id="main-view"]/ms-live/ms-live-event-list/div/ms-grid/ms-event-group/ms-event/div/div/ms-option-group[3]')
for oddH01 in H01:
    print(f"oddH01")
    print(oddH01.text)

H10 = driver.find_elements_by_xpath('//*[@id="main-view"]/ms-live/ms-live-event-list/div/ms-grid/ms-event-group/ms-event/div/div/ms-option-group[4]')
for oddH10 in H10:
    print(f"oddH10")
    print(oddH10.text)

driver.quit()

I've been looking for some days but there was no solution that dide the job like I wanted to Best regards !!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source