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
相关推荐
RaidenLiu17 小时前
告别繁琐:用 Signals 优雅处理 Flutter 异步状态
前端·flutter·前端框架
星链引擎17 小时前
面向API开发者的智能聊天机器人解析
前端
前端Hardy17 小时前
HTML&CSS&JS:纯前端图片打码神器:自定义强度 + 区域缩放,无需安装
前端·javascript·css
道可到17 小时前
35 岁程序员的绝地求生计划:你准备好了吗?
前端·后端·面试
道可到17 小时前
国内最难入职的 IT 公司排行:你敢挑战哪一家?
前端·后端·面试
jnpfsoft17 小时前
低代码应用菜单避坑指南:新建 / 删除 / 导入全流程,路由重复再也不怕!
前端·低代码
Keepreal49617 小时前
word文件预览实现
前端·javascript·react.js
郝开17 小时前
5. React中的组件:组件是什么;React定义组件
前端·javascript·react.js
我是天龙_绍17 小时前
uniapp 中的 #ifndef 条件编译
前端
white-persist17 小时前
SQL 注入详解:从原理到实战
前端·网络·数据库·sql·安全·web安全·原型模式