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
相关推荐
码云数智-大飞2 分钟前
微前端架构落地实战:qiankun vs Module Federation 2026 深度对比与选型指南
前端·架构
ljxp12345683 分钟前
判断两棵二叉树是否相同
python
IT枫斗者7 分钟前
MyBatis批量插入性能优化:从5分钟到3秒的工程化实践
前端·vue.js·mysql·mongodb·性能优化·mybatis
cuber膜拜8 分钟前
LangChain v1.0 Middleware(中间件)使用指南
python·中间件·langchain·langgraph
闲人编程11 分钟前
定时任务与周期性调度
分布式·python·wpf·调度·cron·定时人物·周期性
郝学胜-神的一滴23 分钟前
Python变量本质:从指针哲学到Vibe Coding优化
开发语言·c++·python·程序人生
前端 贾公子25 分钟前
深入理解 Vue3 的 v-model 及自定义指令的实现原理(中)
前端·html
AC赳赳老秦35 分钟前
新能源AI趋势:DeepSeek分析光伏/风电数据,助力2026新能源运维升级
运维·人工智能·python·安全·架构·prometheus·deepseek
Never_Satisfied1 小时前
在HTML & CSS中,img标签固定宽度时,img和图片保持比例缩放
前端·css·html
Cache技术分享1 小时前
327. Java Stream API - 实现 joining() 收集器:从简单到进阶
前端·后端