selenium滚动到页面底部

selenium页面滚动加载到底部

python 复制代码
import time

# 方法:滚动到页面底部
def scroll_to_bottom(driver):
    last_height = driver.execute_script("return document.documentElement.scrollHeight")
    print(f"Initial Document Height: {last_height}")

    while True:
        print("Scrolling down...")
        # 向页面底部滚动
        driver.execute_script("window.scrollTo(0, document.documentElement.scrollHeight);")

        # 等待页面加载
        time.sleep(3)

        # 获取新的页面高度
        new_height = driver.execute_script("return document.documentElement.scrollHeight")
        print(f"New Document Height: {new_height}")

        # 如果新高度和旧高度相同,说明已经到底
        if new_height == last_height:
            print("Reached bottom of the page.")
            break

        last_height = new_height
相关推荐
TestCopilot4 分钟前
从零用 Python 实现最基础的MCP协议
python·mcp
zh1570236 分钟前
CSS如何让元素出现时带抖动_利用关键帧定义抖动动画
jvm·数据库·python
AI技术增长6 分钟前
Pytorch图像去噪实战(五):FFDNet可控图像去噪实战,用噪声强度图解决不同噪声等级问题
pytorch·python·深度学习
fen_fen7 分钟前
下载Chrome浏览器对应的Driver
前端·chrome
路光.8 分钟前
ReferenceError:Can‘t find variable:structureClone
前端·javascript·html·vue2
前端那点事8 分钟前
内存泄漏排查全指南:从场景识别到工具实操,新手也能上手
前端·vue.js
我这一生如履薄冰~12 分钟前
浏览器多窗口同开一页面,数据同步更新(纯前端方案)
前端·javascript
Alice-YUE17 分钟前
前端性能优化完全指南:从指标到实战
前端·学习·性能优化
花月C20 分钟前
Agent应用开发零基础入门:核心概念、环境配置与首次LLM调用
java·python
Momo__21 分钟前
Web Speech API 语音识别与合成详解
前端·javascript