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
相关推荐
2603_955279709 分钟前
C++23新特性在CLion中的实战体验
前端·javascript·c++23
梨子同志10 分钟前
HTTP
前端
weigangwin12 分钟前
LlamaIndex 第一次试用:别先写 RAG Demo,先验上下文合同
python·ai·agent·rag·检索·llamaindex·观测性
省四收割者13 分钟前
一文详解信号完整性(1)
python·嵌入式硬件·数学建模·信息与通信·信号处理·智能硬件
kidding72321 分钟前
旋转大转盘小程序
前端·css·微信小程序·小程序·前端框架
道友可好23 分钟前
Claude Code 泄露源码里的 89 个秘密
前端·人工智能·后端
Tian_Hang28 分钟前
Eclipse Ditto 的权限策略
java·服务器·前端·网络·ide·ubuntu·eclipse
ai生成式引擎优化技术1 小时前
从知识连接到智能组织:WSaiOS认知网络的理论框架与系统设计摘要
网络·python·plotly·django·pygame
用户8356290780511 小时前
使用 Python 保护和取消保护 Excel 工作表和工作簿
后端·python
lichenyang4531 小时前
从 0 新增一个 `has.echo`:我如何理解小程序容器里的 API 调用链路
前端