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
相关推荐
程序员黑豆4 分钟前
鸿蒙应用开发之模拟器安装与使用教程
前端·harmonyos
二宝哥16 分钟前
14.Python模块与包完全指南:从定义到实战
python
王莎莎17 分钟前
MCP 解决的是工具接入,科研 Agent 还缺的是科学证据接口标准化
前端·人工智能
三声三视28 分钟前
交互式用够了?用 Agent SDK 把 Claude 塞进 Python Web 服务
人工智能·python·ai·aigc·ai编程
zhanghaha13141 小时前
Python语言基础:4_数据类型转换
java·前端·python
kyriewen1 小时前
别再写useMemo了——2026年这5个React性能优化已经是反模式
前端·react.js·ai编程
OpenTiny社区1 小时前
TinyRobot v0.5.0 新版本强在哪?
前端·vue.js·github
奇牙coding1 小时前
gpt-5.6-sol 接入指南:reasoning_effort 参数配置、推理链验证与常见报错排查
前端·css·gpt·ai
larance1 小时前
机器学习特征预处理之标准化/归一化
开发语言·python·机器学习
tokenova1 小时前
Python 多模型统一调用封装类,一套代码兼容 GPT/Claude/Grok
python