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
相关推荐
再学一点就睡10 小时前
前端网络实战手册:15个高频工作场景全解析
前端·网络协议
tjjucheng10 小时前
靠谱的小程序定制开发哪个好
python
num_killer10 小时前
小白的Langchain学习
java·python·学习·langchain
WangYaolove131411 小时前
基于深度学习的中文情感分析系统(源码+文档)
python·深度学习·django·毕业设计·源码
C_心欲无痕11 小时前
有限状态机在前端中的应用
前端·状态模式
C_心欲无痕11 小时前
前端基于 IntersectionObserver 更流畅的懒加载实现
前端
candyTong11 小时前
深入解析:AI 智能体(Agent)是如何解决问题的?
前端·agent·ai编程
柳杉11 小时前
建议收藏 | 2026年AI工具封神榜:从Sora到混元3D,生产力彻底爆发
前端·人工智能·后端
weixin_4624462311 小时前
使用 Puppeteer 设置 Cookies 并实现自动化分页操作:前端实战教程
运维·前端·自动化
CheungChunChiu12 小时前
Linux 内核动态打印机制详解
android·linux·服务器·前端·ubuntu