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
相关推荐
jacGJ7 小时前
记录学习--文件读写
java·前端·学习
毕设源码-赖学姐7 小时前
【开题答辩全过程】以 基于WEB的实验室开放式管理系统的设计与实现为例,包含答辩的问题和答案
前端
幻云20107 小时前
Python深度学习:从筑基到登仙
前端·javascript·vue.js·人工智能·python
仰望星空@脚踏实地7 小时前
本地Python脚本是否存在命令注入风险
python·datakit·命令注入
LOnghas12118 小时前
果园环境中道路与树木结构检测的YOLO11-Faster语义分割方法
python
我即将远走丶或许也能高飞9 小时前
vuex 和 pinia 的学习使用
开发语言·前端·javascript
钟离墨笺9 小时前
Go语言--2go基础-->基本数据类型
开发语言·前端·后端·golang
爱吃泡芙的小白白9 小时前
Vue 3 核心原理与实战:从响应式到企业级应用
前端·javascript·vue.js
卓怡学长10 小时前
m115乐购游戏商城系统
java·前端·数据库·spring boot·spring·游戏
2501_9445264210 小时前
Flutter for OpenHarmony 万能游戏库App实战 - 蜘蛛纸牌游戏实现
android·java·python·flutter·游戏