python-3.x - 网页抓取 / 无法点击下一页
问题描述
我想获得下一个网站,例如。在这个网站上: https ://www.11880.com/suche/Naturpark/deutschland
<div class="next">
<form class="link-form" action="https://www.11880.com/form" method="POST">
<input type="hidden" name="source" value="*JSPPyTNQ4Hl4n6FJKGEcgCWqLzgK2zccsymE3agiLSMAKNMw9kRza81Id4CrUpZ08MJMZZgtfLcy7UQJ5Y8LxQ">
<button class="link icon-right" title="Zur nächsten Seite" data-page="1" type="submit">
</button>
</form>
</div>
我尝试使用以下语句单击元素:
driver.find_element_by_xpath ('//*[@id="searchresultlist"]/div/div[1]/div[4]').click()
driver.find_elements_by_class_name("link icon-right").click()
driver.find_element_by_css_selector("[title^='4G Signal quality']")
在第一行我得到这个错误:
selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素 ... 在点 (861、949) 处不可点击。其他元素会收到点击:
...
使用第二行作为尝试,我得到了这个错误:(显然更多的 1 元素与类“link icon-right”一起找到)
Traceback (most recent call last):
File "c:\Users\Polzi\Documents\DEV\Fiverr\papillion\search11880.py", line 80, in <module>
driver.find_elements_by_class_name("link icon-right").click()
AttributeError: 'list' object has no attribute 'click'
并尝试使用第三行,我收到此错误:
selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素在点(566、919)不可点击。其他元素会收到点击:...(会话信息:chrome=91.0.4472.106)
Any ideas how i can get this page right element clicked?
解决方案
“下一页”按钮出现在网页底部。在单击它之前,您必须滚动到该元素。
如下所示:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
next_btn = driver.find_element_by_css_selector(".next")
actions.move_to_element(next_btn).perform()
next_btn.click()
UPD
如果单击“下一步按钮”被 cookie-bar 元素拦截,您可以在单击下一页按钮之前将其关闭
driver.find_element_by_xpath('//button[@class="btn btn-close-cookiebar"]').click()
或者您可以使用 JavaScript 单击“下一页按钮”,而不是使用驱动程序单击它,如下所示:
driver.execute_script("arguments[0].click();", next_btn)
推荐阅读
- eclipse - 除了使用 mvn clean package 之外,如何以稳定的方式将 servlet 项目添加到 Eclipse 中的 Tomcat 服务器
- java - 由于创建任务或键入 antilib:org.apache.ivy.ant.configure,构建失败
- firebase - 接收
() 缺少参数 - Flutter / GetX - c# - 如何在 Glyphs.FontURI 属性中指定 TTC 字体索引?
- sql - SQL Server 成功创建调用 NON-EXISTING 函数的存储过程
- c - 分配块的结构初始化导致分段错误
- android - 将 PDF 保存在 Android 11 上的外部下载目录中
- javascript - 如何在bingmap中获取比例尺
- javascript - 有没有更简单的递归方式来编写这个函数?
- python - python rss feed生成器给出错误的格式