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
相关推荐
4Forsee7 分钟前
【Android】动态操作 Window 的背后机制
android·java·前端
HappRobot10 分钟前
python类和对象
开发语言·python
用户904438163246011 分钟前
从40亿设备漏洞到AI浏览器:藏在浏览器底层的3个“隐形”原理
前端·javascript·浏览器
小二李16 分钟前
第12章 koa框架重构篇 - Koa框架项目重构
java·前端·重构
鸡吃丸子20 分钟前
React Native入门详解
开发语言·前端·javascript·react native·react.js
盼哥PyAI实验室23 分钟前
Python YAML配置管理:12306项目的灵活配置方案
开发语言·python
qq_4287232426 分钟前
英语歌10个月之前启蒙磨耳朵
前端
Hao_Harrision30 分钟前
50天50个小项目 (React19 + Tailwindcss V4) ✨ | DrinkWater(喝水记录组件)
前端·react.js·typescript·vite7·tailwildcss
SadSunset37 分钟前
(19)Bean的循环依赖问题
java·开发语言·前端
JIngJaneIL39 分钟前
基于Java+ vue图书管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端