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
相关推荐
@zulnger8 分钟前
python 学习笔记(多线程和多进程)
笔记·python·学习
UIUV16 分钟前
模块化CSS学习笔记:从作用域问题到实战解决方案
前端·javascript·react.js
aoi17 分钟前
解决 Vue 2 大数据量表单首次交互卡顿 10s 的性能问题
前端·vue.js
Kakarotto17 分钟前
使用ThreeJS绘制东方明珠塔模型
前端·javascript·vue.js
Master_清欢18 分钟前
jupyter新增行数
ide·python·jupyter
donecoding19 分钟前
TypeScript `satisfies` 的核心价值:两个例子讲清楚
前端·javascript
德育处主任19 分钟前
『NAS』在群晖部署一个文件加密工具-hat.sh
前端·算法·docker
cup11321 分钟前
【原生 JS】支持加密的浏览器端 BYOK AI SDK,助力 Vibe Coding
前端
用户120391129472624 分钟前
使用 Tailwind CSS 构建现代登录页面:从 Vite 配置到 React 交互细节
前端·javascript·react.js
杨进军24 分钟前
模拟 Taro 实现编译多端样式文件
前端·taro