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
相关推荐
Momo__9 分钟前
Vue3 v-memo:长列表渲染的性能核武器
前端·vue.js
Forever7_11 分钟前
弃用 Canvas!高性能2D WebGL 引擎性能提升几十倍!
前端·canvas
李白的天不白12 分钟前
webpack 压缩文件
前端·webpack·node.js
闲人编程14 分钟前
Agent的评估体系(AgentEval):如何判断一个Agent好坏?
大数据·人工智能·python·算法·agent·智能体·swe
Momo__16 分钟前
Electron应用性能优化:从启动慢到秒开的7个实战技巧
前端·electron
西洼工作室40 分钟前
UniApp云开发笔记
前端·笔记·uni-app
zhangxingchao1 小时前
AI应用开发一: AI 编程、大模型调用和 Agent
前端·人工智能·后端
m0_702036531 小时前
html标签如何提升可访问性_aria-label与title区别【指南】
jvm·数据库·python
BU摆烂会噶1 小时前
【LangGraph】节点内调用与状态隔离
android·人工智能·python·ui·langchain·人机交互
ㄟ留恋さ寂寞1 小时前
Golang格式化输出占位符都有什么_Golang fmt占位符教程【通俗】
jvm·数据库·python