我是编程初学者。我使用python3
和selenium
从网站的两个元素中获取值。在
我想检索当前和总页数,见下图。在
在我的例子中,当前的页码是43,总页数是510。在
当我检查有问题的元素时,我得到以下源代码:
第一行表示当前页字段,第二行表示总页数。在
我设法检索了这两个元素的xpath,它们是
对于当前页面元素:
'//*[@id="openSDPagerInputContainer2"]/label[2]'
对于total page元素:
^{pr2}$比如:
totalPages = driver.find_element_by_css_selector('afterInput').get_attribute('innerHTML').split()[1]
currentPage = sys.argv[2]
或者:
totalPages = driver.find_elements_by_xpath('//*[@id="openSDPagerInputContainer2"]/label[2]')
currentPage = driver.find_elements_by_xpath('//*[@id="openSDPagerInputContainer2"]/input')
不起作用。对于第一个代码片段,我得到一个selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: afterInput
错误消息,对于第二个代码片段,我得到一个AttributeError: 'list' object has no attribute 'split'
错误消息,如果没有.split()
我将收到错误的输出。在
如何使用selenium
和python3
检索当前和总页码?在
目前没有回答
相关问题 更多 >
编程相关推荐