首页 > 解决方案 > 使用 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)

提前致谢。

标签: pythonweb-scrapingnlpselenium-chromedriver

解决方案


找到了答案。

driver.find_element_by_xpath('//button[normalize-space()="Show more reviews"]').click()

参考 - https://stackoverflow.com/a/48673343/6486100 谢谢@Andersson


推荐阅读