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
相关推荐
陆枫Larry5 小时前
一次登录问题排查:接口没错,错的是旧业务逻辑
前端
小小小小宇5 小时前
大模型打分与采样原理,以及 Pi Agent 核心原理
前端
XZ-0700015 小时前
week2-1-可视化
开发语言·python
Java后端的Ai之路5 小时前
14、Python - 责任链模式
服务器·开发语言·人工智能·python·责任链模式
张人玉5 小时前
基于 Python 机器学习 与 PyQt5 桌面框架开发的可视化分析系统——基于大数据的网上购物消费行为分析可视化大屏
python·qt·机器学习·echarts·three.js
一位正在转型AI全栈的前端工程师6 小时前
AI 全栈学习之旅 -Week 5:RAG 知识库问答系统:从零到生产级部署的全栈实践总结
前端·python
2601_962381866 小时前
Python办公联动:Excel数据一键自动生成PPT图表
python·数据分析·自动化·excel·ppt
东莞市永盛电气6 小时前
三相208V变380V变压器,出海工业设备供电适配方案
python·单片机·嵌入式硬件
光影少年6 小时前
react navite 安卓iOS 打包、签名、环境区分
前端·react native·react.js
coderCN6 小时前
Nodejs 第三十四章 数据库(表达式和函数、子查询和连表)
前端·node.js