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
相关推荐
2301_81527952几秒前
mysql如何使用yum安装mysql_配置官方yum源与自动安装
jvm·数据库·python
吴声子夜歌2 分钟前
Vue3——Vuex状态管理
前端·vue.js·vue·es6
qq_12084093713 分钟前
Three.js 工程向:Frustum Culling 与场景分块优化实战
前端·javascript
weixin_458580124 分钟前
MySQL跨版本迁移数据格式不兼容_使用mysqldump全量导出导入
jvm·数据库·python
Greyson17 分钟前
SQL触发器在导入大文件时如何跳过_使用禁用触发器语句导入
jvm·数据库·python
漫游的渔夫8 分钟前
从 Fetch 到 RAG:为什么你的 AI 知识库总是“胡言乱语”?
前端·人工智能
Full Stack Developme9 分钟前
Hutool JSON 操作教程
windows·python·json
Amos_Web10 分钟前
谷歌浏览器插件Brower-Books: 把整个浏览器变成你的云端书架
前端·chrome·产品
2401_8877245010 分钟前
Redis怎样统计独立访客UV_基于Set的SADD指令天然去重特性
jvm·数据库·python
qq_2837200513 分钟前
Python3 模块精讲:pyecharts —— 交互式数据可视化全解与实战
python·信息可视化·数据分析·echarts·数据可视化·pyecharts