在python中使用硒抓取赔率

时间:2020-04-14 09:44:35

标签: python selenium selenium-webdriver

我想通过Chrome驱动程序在Python中使用Selenium来刮取此页面

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

我只对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)

我编写了这行代码,但是我只能在10Bet行中刮取表的第一个奇数,但希望在bet365行中以开数开头。

2 个答案:

答案 0 :(得分:0)

您可以找到表中的所有行,然后测试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

答案 1 :(得分:0)

完美的作品。我会通过提取开局赔率来完善

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)   

但是我得到了这个错误 AttributeError:“列表”对象没有属性“文本”