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
相关推荐
米丘11 分钟前
vue-router v5.x 路由模式关于 createWebHistory、 createWebHashHistory的实现
前端
本末倒置18311 分钟前
Bun 内置模块全解析:告别第三方依赖,提升开发效率
前端·javascript·node.js
踩着两条虫12 分钟前
AI 驱动的 Vue3 应用开发平台 深入探究(二):核心概念之DSL模式与数据模型
前端·vue.js·ai编程
牛奶25 分钟前
200 OK不是"成功"?HTTP状态码潜规则
前端·http·浏览器
Hilaku1 小时前
OpenClaw 很爆火,但没人敢聊它的权限安全🤷‍♂️
前端·javascript·程序员
ConardLi2 小时前
OpenClaw 完全指南:这可能是全网最新最全的系统化教程了!
前端·人工智能·后端
丁哥2 小时前
99.9%纯AI 做了一个ICO图标生成器(免费 全尺寸 不限文件大小)2ICO.CN欢迎品鉴
前端
Lupino2 小时前
别再只聊 AI 写代码了:技术负责人要把“变更治理”提到第一优先级
python·docker·容器
兆子龙2 小时前
React Native 完全入门:从原理到实战
前端·javascript
哇哇哇哇2 小时前
vue3 watch解析
前端