【发布时间】:2021-03-16 21:11:53
【问题描述】:
我在使用 Python Selenium 向下滚动无限滚动页面时遇到了一些问题。我想向下滚动this 页面,以便我可以点击页面上的每部电影。代码运行到最后并退出驱动程序但没有向下滚动页面 - 出了什么问题?
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()
【问题讨论】:
-
我正在尝试让页面向下滚动。如果需要,我可以丢失这行代码 - 我的首要任务是让页面向下滚动。
标签: python python-3.x selenium selenium-webdriver infinite-scroll