【发布时间】:2021-10-10 15:50:44
【问题描述】:
我已经阅读了this 的答案,但是,我需要逐步滚动网页,因为如果我直接滚动到文档的高度,则不会加载图像,只有 base64url 中的占位符。 我想滚动一点,直到我到达网页的末尾,确保我可以在驱动程序中看到图像,以便加载它们。
有什么方法可以做到这一点?
我目前的功能:
def scroll_to_bottom(driver):
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
# Scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(2)
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
这直接进入底部,但如果该项目在过去一段时间内没有聚焦,它将不会加载我需要的图像。
【问题讨论】: