用蟒蛇中的硒刮赔率



我想用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"对象没有属性"text">

最新更新