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 小时前
004.环境搭建基础篇:Python、CUDA、cuDNN、PyTorch/TensorFlow安装与版本兼容性踩坑
pytorch·python·tensorflow
灵感__idea7 小时前
Hello 算法:贪心的世界
前端·javascript·算法
知行合一。。。8 小时前
Python--04--数据容器(总结)
开发语言·python
架构师老Y8 小时前
008、容器化部署:Docker与Python应用打包
python·容器·架构
lifewange8 小时前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
GreenTea9 小时前
一文搞懂Harness Engineering与Meta-Harness
前端·人工智能·后端
pluvium279 小时前
记对 xonsh shell 的使用, 脚本编写, 迁移及调优
linux·python·shell·xonsh
2401_827499999 小时前
python项目实战09-AI智能伴侣(ai_partner_5-6)
开发语言·python
PD我是你的真爱粉9 小时前
MCP 协议详解:从架构、工作流到 Python 技术栈落地
开发语言·python·架构
ZhengEnCi9 小时前
P2G-Python字符串方法完全指南-split、join、strip、replace的Python编程利器
python