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
相关推荐
向阳蒲公英4 分钟前
Pycharm2025版本配置Anaconda步骤
python
每天吃饭的羊4 分钟前
媒体查询
开发语言·前端·javascript
Darkershadow10 分钟前
蓝牙学习之uuid与mac
python·学习·ble
北海有初拥13 分钟前
Python基础语法万字详解
java·开发语言·python
XiaoYu200229 分钟前
第8章 Three.js入门
前端·javascript·three.js
这个一个非常哈39 分钟前
element之,自定义form的label
前端·javascript·vue.js
Mqh1807621 小时前
day61 经典时序模型3
python
我想吃烤肉肉1 小时前
logger比print优秀之处
python
阿东在coding1 小时前
Flutter 测试框架对比指南
前端
Cosmoshhhyyy1 小时前
《Effective Java》解读第32条:谨慎并用泛型和可变参数
java·python