繁体   English   中英

在 python 中使用 selenium 刮赔率

[英]scrape odds using selenium in python

我想用 Chrome 驱动程序在 Python 中使用 Selenium 刮掉这个页面

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

我只对 Bet365 的开盘赔率感兴趣。

在此处输入图像描述

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 行上的开盘奇数。

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

完美它的工作原理。 我会通过提取开盘赔率来改进

在此处输入图像描述

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

但我收到此错误 AttributeError: 'list' object has no attribute 'text'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM