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
相关推荐
tiandyoin2 分钟前
Brave(Chrome)浏览器设置选项中文注解
前端·chrome·设置·brave
3DVisionary4 分钟前
捕捉亚毫米级裂纹演化!DIC技术为裂纹扩展与抗裂研究带来全新方案
人工智能·python·3d·应变测量·金属3d打印·dic精度检验方法·各向异性
smchaopiao6 分钟前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
sibylyue12 分钟前
Typescritpt、ES6
前端·javascript·vue.js
用户30767528112713 分钟前
《拒绝卡顿:深入解析 AI 流式 Markdown 的高性能渲染架构》
前端·javascript
Mertens187415 分钟前
Zero-Doc:极简的 Spec Coding 落地指南
前端·javascript·ai编程
毛骗导演15 分钟前
万字解析 OpenClaw 源码架构-跨平台应用之MacOS 应用
前端·架构
ZengLiangYi16 分钟前
用 1300 行原生 JS 做了一个 Chrome DevTools 扩展,让前后端不再为接口报错截图扯皮
前端·javascript
A_Qyp16 分钟前
JeechBoot前端表格内操作设置下拉
前端·javascript
YimWu17 分钟前
面试官:OpenCode Agent 代理机制了解吗?
前端·agent·ai编程