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
相关推荐
Rin__________20 分钟前
Python计算机视觉 第8章-图像内容分类
python·计算机视觉·分类
西猫雷婶24 分钟前
python画图|3D直方图基础教程
开发语言·python
守望↪星空27 分钟前
画图方法总结
python
码农超哥同学43 分钟前
Python知识点:如何使用Python进行Excel文件操作(OpenPyXL、Pandas)
python·面试·excel·pandas·编程
不良人龍木木1 小时前
sqlalchemy FastAPI 前端实现数据库增删改查
前端·数据库·fastapi
一只会敲代码的小灰灰1 小时前
python学习第九节:爬虫实战-抓取地址库
爬虫·python·学习
AI原吾1 小时前
探索自动化的魔法:Python中的pyautogui库
运维·python·自动化
长风清留扬1 小时前
Python “集合” 100道实战题目练习,巩固知识、检查技术
数据结构·python·面试·跳槽·学习方法·集合·改行学it
c1tenj22 小时前
Jedis,SpringDataRedis
前端
Code成立2 小时前
HTML5中IndexedDB前端本地数据库
前端·数据库·html5·indexeddb