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
相关推荐
Moment1 小时前
腾讯终于对个人开放了,5 分钟在 QQ 里养一只「真能干活」的 AI 😍😍😍
前端·后端·github
比尔盖茨的大脑1 小时前
AI Agent 架构设计:从 ReAct 到 Multi-Agent 系统
前端·人工智能·全栈
天才熊猫君1 小时前
使用 Vite Mode 实现客户端与管理端的物理隔离
前端
HelloReader2 小时前
React Hook 到底是干嘛的?
前端
用户60572374873082 小时前
OpenSpec 实战:从需求到代码的完整工作流
前端·后端·程序员
寅时码2 小时前
React 正在演变为一场不可逆的赛博瘟疫:AI 投毒、编译器迷信与装死的官方
前端·react.js·设计模式
忆江南2 小时前
HTTP 各版本演进与 HTTPS 原理详解
前端
忆江南2 小时前
对组件化与模块化的思考与总结
前端
小码哥_常2 小时前
从0到1:Android组件化架构搭建秘籍
前端