如何使用selenium获取分页的html表的所有元素?

时间:2016-09-21 09:00:11

标签: python python-2.7 selenium selenium-webdriver selenium-chromedriver

我有一个带有桌子的网页。该表格每页有7个条目。我想访问表的所有元素。

table_element = driver.find_element_by_xpath(xpath)
for tr in table_element.find_elements_by_tag_name('tr'):
    print tr.text

使用上面的代码,我只能获取第一页中的元素,但不能获取同一个表的后续页面。我怎样才能获得所有元素?

sample image of the table

1 个答案:

答案 0 :(得分:0)

在您提供的代码之外,您需要一个循环,用于单击下一页链接(或等效链接),直到下一页链接不再存在。没有任何HTML,我们无法提供更具体的答案。