Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium-如何循环到最后一个<;李>;站点中的元素_Python_Selenium_Selenium Webdriver_Xpath_Webdriver - Fatal编程技术网

Python Selenium-如何循环到最后一个<;李>;站点中的元素

Python Selenium-如何循环到最后一个<;李>;站点中的元素,python,selenium,selenium-webdriver,xpath,webdriver,Python,Selenium,Selenium Webdriver,Xpath,Webdriver,我已经创建了一个python selenium脚本,该脚本应该在网站中导航并收集人员配置文件()。该程序不会通过循环页面来收集链接。我用过这个,但不起作用 try: # this is navigate to next page driver.find_element_by_xpath('//div[@id="searchResultsSection"]/ul/li[12]').click() time.sleep(1) except NoSuchElement

我已经创建了一个python selenium脚本,该脚本应该在网站中导航并收集人员配置文件()。该程序不会通过循环页面来收集链接。我用过这个,但不起作用

 try:
     # this is navigate to next page
     driver.find_element_by_xpath('//div[@id="searchResultsSection"]/ul/li[12]').click()
     time.sleep(1)
 except NoSuchElementException:
     break
“下一步”按钮后面的语法如下所示

<a href="" onclick="PageRequest('2', event)" class="xh-highlight">&gt;</a>


有人不知道如何编写代码来单击“下一步”按钮吗?

您可以自己编写:

  • ctrl+shift+i
  • 右键单击下一步按钮->检查
  • 右键单击下一个按钮“代码->复制->复制选择器”
然后将该按钮存储在WebElement下一个按钮中

nextButton.click();

您可以尝试使用下面的行单击“下一步”按钮

driver.find_element_by_link_text(">").click()
如果查看图像为
的元素的HTML,它是
标记的最后一个
  • 标记中的
    标记。因此,要在其上调用
    click()
    ,可以使用以下代码块:

    driver.find_element_by_xpath("//ul[@class='results-pagination']/li[last()]/a").click()
    

    为什么?这充其量只是道德问题。非常感谢你的帮助