python - 使用 Python Selenium 在网页中单击“显示更多交易”
问题描述
我正在使用以下代码单击“显示更多评论”按钮,但无法正常工作。
代码:
link= 'https://www.capterra.com/p/5938/Oracle-Database/'
driver.get(link)
while True:
try:
driver.find_element_by_partial_link_text('Show more reviews').click()
# Wait till the container of the recipes gets loaded
# after load more is clicked.
time.sleep(5)
except (NoSuchElementException, WebDriverException) as e:
break
page_source = driver.page_source
#BEAUTIFUL SOUP OPTION
soup = BeautifulSoup(page_source,"lxml")
错误声明
NoSuchElementException: no such element: Unable to locate element: {"method":"partial link text","selector":"Show more reviews"}
(Session info: headless chrome=76.0.3809.132)
提前致谢。
解决方案
找到了答案。
driver.find_element_by_xpath('//button[normalize-space()="Show more reviews"]').click()
参考 - https://stackoverflow.com/a/48673343/6486100 谢谢@Andersson
推荐阅读
- python - 函数内“finally”块的奇怪行为
- c# - C#:在 JPEG 文件中保留 COM 标记(无 EXIF)
- azure-active-directory - Microsoft Graph API 错误:unauthorized_client 与 WSO2 EI 集成时
- php - 在多语言网站上通过 AJAX 查询自定义帖子类型
- r - R对多列进行分组并为它们指定行
- playwright - 描述 Playwright 中的覆盖可能吗?
- java - 如何从 Spring Boot 应用程序中排除 spring-boot-startar-web 自动配置?
- r - 将 NA 左侧的值转换为整个数据帧的 NA 值
- file-io - 如何将terraform创建的VM的IP地址存储在文本文件中
- chef-infra - Chef - 无法设置从 ruby_block 传递的 registry_key 值