0
votes

I want to scrape this page, using Selenium in Python with Chrome driver

https://www.betexplorer.com/soccer/england/premier-league-2018-2019/brighton-manchester-city/UFOgEYGu/

I am interested only on opening odds of Bet365.

enter image description here

bet365_row = driver.find_element_by_xpath("//div[@id='odds-content']").find_element_by_tag_name('tbody').find_element_by_xpath("//tr[@data-bid='16']")
odd1= driver.find_element_by_xpath("//tr[@data-originid='1']").find_element_by_xpath("//td[@class='table-main__detail-odds table-main__detail-odds--first']").find_element_by_xpath("//span[@class='table-main__detail-odds--hasarchive']").text
print(odd1)

I write this lines of the code, but i can scrape only the first odd of the table on 10Bet row, but wish the opening odd on bet365 row.

2
To get all the odd you have to add an 's' to element in driver.find_element_by_xpath in other words you'll get only the first occurence. try : driver.find_elements_by_xpath(...) - Y.Berrama
driver.find_elements_by_xpath("//div[@id='odds-content']") bet365odd=driver.find_elements_by_xpath("//tr[@data-bid='16']").find_elements_by_xpath("//tr[@data-originid='1']").find_elements_by_xpath("//td[@class='table-main__detail-odds table-main__detail-odds--first']").find_elements_by_xpath("//span[@class='table-main__detail-odds--hasarchive']").text i write this, add find_elements, but i got this error: AttributeError: 'list' object has no attribute 'find_elements_by_xpath' - pygian81
Yes because find_elements_by_xpath return a list of selenium object. If it was me i would do something like this (look in my edited response) - Y.Berrama

2 Answers

0
votes

You can find all the rows in the table an then test wich row has bet365:

trs = browser.find_elements_by_xpath(".//div[@id='odds-content']/div/div/table/tbody/*")


for tr in trs:
    if "bet365" in tr.text:
        print(tr.text)
        # Do whatever you want
0
votes

Perfect it works. I would refine by extracting opening odds

enter image description here

 for tr in trs:
    if "bet365" in tr.text:
        odd = driver.find_elements_by_class_name('data-opening-odd').text()
        print(odd)   

But i got this error AttributeError: 'list' object has no attribute 'text'