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
相关推荐
曲幽15 小时前
FastAPI 身份验证总踩坑?这份 FastAPI Users “避坑指南”请收好
python·fastapi·web·jwt·oauth2·user·authentication
装不满的克莱因瓶15 小时前
掌握 RNN 与 LSTM 模型结构
人工智能·python·rnn·深度学习·神经网络·ai·lstm
云水一下16 小时前
TypeScript 从零基础到精通(五):高级类型与泛型
前端·javascript·typescript
何以解忧,唯有..16 小时前
Python包管理工具pip:从入门到精通
开发语言·python·pip
counterxing16 小时前
vibe coding 之后,我更不想打字了
前端·agent·ai编程
金銀銅鐵16 小时前
用 Tkinter 实现简单的猜数字游戏
后端·python
copyer_xyf16 小时前
Python 模块与包的导入导出
前端·后端·python
研☆香16 小时前
es6新特性功能介绍(四)
前端·ecmascript·es6
微扬嘴角16 小时前
React篇1--JSX语法规则、组件、组件实例的3大特性
前端·react.js·前端框架
ice81303318117 小时前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib