【发布时间】:2019-04-21 06:04:33
【问题描述】:
我正在尝试在 python 中使用 selenium web 驱动程序提取 NBA 球员的统计数据,这是我的尝试:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
browser = webdriver.Chrome()
browser.get('https://www.basketball-reference.com')
xp_1 = "//select[@id='selector_0' and @name='team_val']"
team = Select(browser.find_element_by_xpath(xp_1))
team.select_by_visible_text('Golden State Warriors')
xp_2 = "//select[@id='selector_0' and @name='1']"
player = Select(browser.find_element_by_xpath(xp_2))
player.select_by_visible_text('Jordan Bell')
我遇到的问题是此页面中有 4 个“开始”按钮,并且都具有相同的输入功能。换句话说,下面的 xpath 返回 4 个按钮:
//input[@type='submit'and @name="go_button" and @id="go_button" and @value="Go!"]
我尝试如下添加祖先但未成功,但它没有返回 xpath:
//input[@type='submit' and @name="go_button" and @id="go_button" and @value="Go!"]/ancestor::/form[@id='player_roster']
感谢任何见解!
【问题讨论】:
标签: python selenium xpath web-scraping selenium-chromedriver