简体   繁体   English

Python Selenium-如何单击Web表列的每个行元素?

[英]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 need a way to count the rows 我需要一种计算行数的方法
  • Then I need to tell the WebDriver to loop/click through elements in the FGM column for the row count 然后,我需要告诉WebDriver循环/单击FGM列中的元素以获取行数

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.

相关问题 Python Selenium Web Automation 如何单击登录按钮 - Python Selenium Web Automation How Do You Click A Login Button Python Selenium:获取表格中某个元素的行列 - Python Selenium: Obtain row and column of an element in a table 如何使用硒在表格中查找一行并单击表格元素? - How to find a row and click a table element across the table with selenium? Python Selenium单击表中包含正确数据的特定行 - Python Selenium click on a specific row in a table containing the right data in a column Selenium - Python 如何在里面一一点击行元素<table><tr>环形 - Selenium - Python How to click row element one by one inside <table><tr> loop 您如何找到并单击此按钮? 使用 python 和 selenium 到 web 自动化 - How do you locate and click on this button? Using python and selenium to web automate 如何在python selenium中点击web元素列表中的第二个元素? - How to click on second element from list of web element in python selenium? 如何点击使用Selenium WebDriver隐藏的元素? - How do you click on an element which is hidden using Selenium WebDriver? 如何在 Selenium Python 的 table/tbody 中找到的每个元素上单击()? - How to do click() ove each element found in table/tbody in Selenium Python? 如何使用 selenium 单击表格中的元素? - How to click element in table with selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM