url = correct_url(url)
browser = webdriver.Chrome()
browser.get(url)
browser.find_element_by_xpath('//*[@title="New chat"]').click()
drawer_body = browser.find_elements_by_class_name('drawer-body')
browser.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', drawer_body)
Get the 'div' element, this has a list and will be scrolled
drawer_body = browser.find_elements_by_class_name('抽屉体')
The line below scrolls very fast and reaches the bottom but this does not load data. Is there any way I can slowly scroll into drawer_body element?.
browser.execute_script('参数[0].scrollTop = 参数[0].scrollHeight',抽屉体)
我正在尝试使用 python 和 selenium 实现以下脚本。 http://ctrlq.org/code/19966-whatsapp-phone-numbers
最佳答案
大多数浏览器支持空格键键作为向下滚动页面的键盘快捷键。使用此功能,您可以执行以下操作:
- 访问页面
- 解析目前加载的内容
- 使用 Selenium 模拟按空格键
- 等待 2-3 秒,直到加载更多数据
- 继续
还有一个提示:为了避免陷入永远循环,您需要检查新加载的数据是否与按空格键之前的数据不同,否则脚本应该退出,因为没有新数据可供解析。
关于javascript - 在 python selenium javascript 中缓慢滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38773273/