gpt4 book ai didi

python - 使用 selenium 在 nytimes.com 上单击 "show more"按钮

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:50 26 4
gpt4 key购买 nike

我正在尝试滚动 this页。向下滚动到页面底部后,我需要单击“显示更多”按钮,但我无法使用 selenium 找到它。

self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
self.driver.find_element_by_class_name('button load-more-button').click()

但是我得到一个InvalidSelectorException

最佳答案

使用下面的代码:

elem = self.driver.find_element_by_css_selector(".button.load-more-button[aria-controls$='set-latest']");


//this line will scroll down to make element visible
self.driver.execute_script("window.scrollTo(" + elem.getLocation().x + "," +(elem.getLocation().y- 100) + ");");

elem.click();

关于python - 使用 selenium 在 nytimes.com 上单击 "show more"按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37341667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com