[英]Python Selenium - How do you click on every row element for column of web table?
This may be a two part question so forgive me if this isn't well written: 这可能是一个分为两部分的问题,如果编写得不好,请原谅我:
I'm trying to get my WebDriver to go to the nba team stats page: http://stats.nba.com/teams/traditional/#!?sort=W_PCT&dir=-1 我正在尝试让我的WebDriver转到nba团队统计信息页面: http : //stats.nba.com/teams/traditional/#!? sort=W_PCT&dir=-1
Table Image for Reference 表格图片供参考
and then click the linked FGM numbers in the table. 然后单击表中链接的FGM编号。 This should open a new tab in the background.
这应该在后台打开一个新选项卡。 So far I'm completely lost how I should be approaching this.
到目前为止,我已经完全迷失了应该如何实现这一目标。
I'm thinking: 我在想:
I'm sure I can get the data with BeautifulSoup but I'm trying to practice with Selenium and working with tables/links that can vary in length. 我确定可以使用BeautifulSoup获取数据,但我正在尝试使用Selenium并使用长度可能有所变化的表/链接。 Any leads are appreciated.
任何线索表示赞赏。 Thanks!
谢谢!
Python example: Python示例:
from selenium import webdriver
from selenium.webdriver import ActionChains
web_driver = webdriver.Firefox()
web_driver.get("http://stats.nba.com/teams/traditional/#!?sort=W_PCT&dir=-1")
actions = ActionChains(driver)
team_links = webdriver.find_elements_by_xpath("//body//td[contains(@class, 'first')]/a")
for link in team_links:
actions.key_down(Keys.CONTROL).click(link).key_up(Keys.CONTROL).perform()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.