Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium不向下滚动无限页面_Python_Python 3.x_Selenium_Selenium Webdriver_Infinite Scroll - Fatal编程技术网

Python Selenium不向下滚动无限页面

Python Selenium不向下滚动无限页面,python,python-3.x,selenium,selenium-webdriver,infinite-scroll,Python,Python 3.x,Selenium,Selenium Webdriver,Infinite Scroll,我在使用Python Selenium向下滚动无限滚动页面时遇到一些问题。我想向下滚动页面,这样我就可以点击页面上的每一部电影。代码运行到最后并退出驱动程序,但没有向下滚动页面-怎么了 def scroll(driver): timeout = 5 # Get scroll height last_height = driver.execute_script("return document.body.scrollHeight") whil

我在使用Python Selenium向下滚动无限滚动页面时遇到一些问题。我想向下滚动页面,这样我就可以点击页面上的每一部电影。代码运行到最后并退出驱动程序,但没有向下滚动页面-怎么了

def scroll(driver):
    timeout = 5

    # Get scroll height
    last_height = driver.execute_script("return document.body.scrollHeight")

    while True:
        # Scroll down to bottom
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

        # load the website
        time.sleep(5)

        # Calculate new scroll height and compare with last scroll height
        new_height = driver.execute_script("return document.body.scrollHeight")

driver.get("https://www.justwatch.com/uk/provider/bfi-player/movies")
scroll(driver)
driver.quit()
尝试使用以下方法:

import time
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.justwatch.com/uk/provider/bfi-player/movies")
time.sleep(3)
driver.execute_script("document.body.getElementsByTagName('ion-content')[0].scrollToBottom();")
time.sleep(3)
driver.quit()
尝试使用以下方法:

import time
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.justwatch.com/uk/provider/bfi-player/movies")
time.sleep(3)
driver.execute_script("document.body.getElementsByTagName('ion-content')[0].scrollToBottom();")
time.sleep(3)
driver.quit()
您应该在scrollelement上进行滚动,因为滚动条也是页面中的一个元素。但是滚动条在shadowRoot中,所以使用execute\u脚本


您应该在scrollelement上进行滚动,因为滚动条也是页面中的一个元素。但是滚动条在侧阴影根目录中,所以使用执行脚本

我试图让页面向下滚动。如果需要,我可能会丢失这行代码-我的首要任务是让页面向下滚动。我正在尝试让页面向下滚动。如果需要,我可能会丢失这行代码-我的首要任务是让页面向下滚动。此代码引发此异常:引发异常\u类(消息、屏幕、堆栈跟踪)selenium.common.exceptions.JavascriptException:消息:javascript错误:无法读取的属性“scrollToBottom”undefined@Eddyhut怪人,我的很好用,尝试打开浏览器->移动到您的url->定义工具->控制台并运行该命令:
document.body.getElementsByTagName('ion-content')[0].scrollToBottom()此代码引发此异常:引发异常\u类(消息、屏幕、堆栈跟踪)selenium.common.exceptions.JavascriptException:消息:javascript错误:无法读取的属性“scrollToBottom”undefined@Eddyhut怪人,我的很好用,尝试打开浏览器->移动到您的url->定义工具->控制台并运行该命令:
document.body.getElementsByTagName('ion-content')[0].scrollToBottom()还没拿到,接得好!您的代码也应该可以工作,但还没有达到它,很好的捕获!您的代码也应该工作