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
相关推荐
sunywz11 分钟前
【JVM】(2)java类加载机制
java·jvm·python
冴羽12 分钟前
JavaScript Date 语法要过时了!以后用这个替代!
前端·javascript·node.js
加油乐14 分钟前
react使用Ant Design
前端·react.js·ant design
OEC小胖胖14 分钟前
05|从 `SuspenseException` 到 `retryTimedOutBoundary`:Suspense 的 Ping 与 Retry 机制
前端·前端框架·react·开源库
Silence_Jy14 分钟前
GPU架构
python
kwg12619 分钟前
本地搭建 OPC UA MCP 服务
python·agent·mcp
belldeep21 分钟前
python:mnist 数据集下载,parse
python·numpy·mnist
攀登的牵牛花25 分钟前
前端向架构突围系列 - 框架设计(三):用开闭原则拯救你的组件库
前端·架构
前端小L31 分钟前
专题一:搭建测试驱动环境 (TypeScript + Vitest)
前端·javascript·typescript·源码·vue3