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
相关推荐
念恒123065 分钟前
Python(复杂判断)
python·学习
追风筝的人er5 分钟前
SpringBoot+Vue3 企业考勤如何处理法定假期?节假日方案、调休补班与工作日判断链路拆解
前端·vue.js·后端
无敌的黑星星15 分钟前
Java8 CompletableFuture 实战指南
linux·前端·python
StockTV26 分钟前
印度股票实时数据 NSE和BSE的实时行情、K 线及指数数据
java·开发语言·spring boot·python
chaofan98026 分钟前
GPT-5.5 领衔 Image 2.0:像素级控制时代,AI 绘图告别开盲盒
开发语言·人工智能·python·gpt·自动化·api
雁鸣零落29 分钟前
如何在 Chrome 中查看其他浏览器的书签?书签空间订阅与侧边栏只读切换指南
前端·chrome·edge浏览器
七颗糖很甜36 分钟前
“十五五”气象发展规划:聚焦五大核心任务
大数据·python·算法
爱码小白1 小时前
Python 异常处理 完整学习笔记
开发语言·python
hpoenixf1 小时前
一天上线 + 零返工:我如何给复杂前端需求建立“安全感”
前端
芝士就是力量啊 ೄ೨1 小时前
Python如何编写一个简单的类
开发语言·python