![](/img/trans.png)
[英]Using Selenium to scrape a table across multiple pages when the url doesn't change
[英]Looping through table rows when the url doesn't change with selenium
您可以使用 xpath 选择循环中的每一行。
//*[@id="left-sidebar"]/div[1]/nav/ol/li[2]/ol/li[x] // Where x is your loop iterator
你可以用 css 选择器做同样的事情
#left-sidebar > div.left-sidebar--sticky-container.js-sticky-leftnav > nav > ol > li:nth-child(x) // Where x is your loop iterator
这当然是一个例子(元素是stackoverflow左侧栏上的li)
编辑:代码示例
var elements = driver.FindElements(By.XPath("//*[@id='tableau']/tbody/tr"));
for (int x = 0; x < firstResult.Count; x++)
{
var tr = driver.FindElement(By.XPath($"//*[@id='tableau']/tbody/tr[{ x }]"));
// Without selecting
var tr = elements[x];
}
看看这是否有效:
tableRows = driver.find_elements_by_xpath("//div[@class='v-data-table__wrapper']/table/tbody/tr")
for tr in tableRows:
tr.click()
//do the check on the details page
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.