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
相关推荐
2301_815645385 分钟前
css基础
前端·css
Hilaku12 分钟前
求求你们🙏 ,别再换打包工具了?
前端·javascript·程序员
用户新13 分钟前
V8引擎 精品漫游指南--Ignition篇(下 二) JavaScript 栈帧详解
前端·javascript
MATLAB代码顾问14 分钟前
【智能优化】鹈鹕优化算法(POA)原理与Python实现
开发语言·python·算法
账号已注销free14 分钟前
box-shadow完整用法
前端
得闲喝茶21 分钟前
JavaScript在数据处理的应用
开发语言·前端·javascript·经验分享·笔记
研究点啥好呢25 分钟前
凯捷 自动化测试(Java+Selenium)面试题精选:10道高频考题+答案解析
java·开发语言·python·selenium·测试工具·求职招聘
SilentSamsara32 分钟前
生成器进阶:`yield from`、协程历史与双向通信
开发语言·python·青少年编程·pycharm
前端那点事1 小时前
Vue3 script setup 语法糖最全教程!零基础吃透+项目落地+面试满分
前端·vue.js
张二娃同学1 小时前
专栏第01篇_深度学习导论
人工智能·python·深度学习·cnn