请问python+selenium对 油管进行爬虫遇到的滑轮无法滑到最底层的问题
js = "window.scrollTo(window.pageXOffset, document.body.scrollHeight)"
driver.execute_script(js)
这是我的代码,在其他网站均可以将滑轮移到最下面但是在油管无法移动滑轮,我也查看了是否为嵌套的ifame的原因但是切换iframe也无法解决该问题,请问是什么原因
以下是油管网站,需要V彭N才能访问:
https://www.youtube.com/watch?v=K56Z12XNQ5c
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
对于像你发的这是无线滚动的所以可以如下:
SCROLL_PAUSE_TIME = 0.5
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(SCROLL_PAUSE_TIME)
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
或者可以选择一个元素。xxx.sendKeys(Keys.PAGE_DOWN);
可否尝试上下移动或者模拟鼠标操作去解题呢
python爬虫selenium页面滑动案例
https://blog.csdn.net/weixin_48964486/article/details/122657417
可以尝试直接模拟鼠标滚轮滚动
pyautogui.scroll(-10000000)