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
相关推荐
花酒锄作田3 小时前
Postgres - Listen/Notify构建轻量级发布订阅系统
python·postgresql
Thomas.Sir4 小时前
第二章:LlamaIndex 的基本概念
人工智能·python·ai·llama·llamaindex
徐小夕4 小时前
我用 AI 撸了个开源"万能预览器":浏览器直接打开 Office、CAD 和 3D 模型
前端·vue.js·github
m0_694845574 小时前
Dify部署教程:从AI原型到生产系统的一站式方案
服务器·人工智能·python·数据分析·开源
小码哥_常4 小时前
Flutter Android 延迟加载代码指南:提升应用性能的关键
前端
这是个栗子4 小时前
TypeScript(三)
前端·javascript·typescript·react
kvo7f2JTy4 小时前
基于机器学习算法的web入侵检测系统设计与实现
前端·算法·机器学习
北风toto5 小时前
前端CSS样式详细笔记
前端·css·笔记
nanfeiyan5 小时前
git commit
前端
李昊哲小课5 小时前
Python办公自动化教程 - 第7章 综合实战案例 - 企业销售管理系统
开发语言·python·数据分析·excel·数据可视化·openpyxl