获取Selenium Python数据行表中的第二个tr

时间:2018-03-04 23:26:30

标签: python selenium web-scraping

我想抓住体育数据。

* object 'spec' not found

这样可以,但它只能从第一场比赛(来自allgames= driver.find_element_by_id("games") box=allgames.find_element_by_link_text("Box Score") )获得分数得分

我正在尝试找到一种方法,我可以转到tr data-row="0",然后使用tr data-row="1"

HTML图片:

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以使用xpath或css来获取这些元素。请参阅Selenium的examples这些方法。

在你的情况下:

trs = allgames.find_elements_by_xpath("//tr")

这为您提供了tr中存储的元素中的所有allgames元素。

答案 1 :(得分:0)

有两种方法可以解决这个问题。

sys.exit

另一种方法是将xpath用作建议的@Alex,但要指定所需的确切属性。

# find all tr tags within the game
tr_list = allgames.find_elements_by_tag_name('tr')
# select the Box Score
tr_list[1].find_element_by_link_text("Box Score")
相关问题