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
相关推荐
一分半心动5 分钟前
清理C盘的python脚本
开发语言·python
进击的野人27 分钟前
Vue Router 深度解析:从基础概念到高级应用实践
前端·vue.js·前端框架
北慕阳28 分钟前
健康管理前端记录
前端
1024小神29 分钟前
cloudflare的worker中的Environment环境变量和不同环境配置
前端
栀秋66637 分钟前
从零开始调用大模型:使用 OpenAI SDK 实现歌词生成,手把手实战指南
前端·llm·openai
l1t37 分钟前
DeepSeek总结的算法 X 与舞蹈链文章
前端·javascript·算法
AI手记叨叨39 分钟前
Python数学:几何运算
python·数学·解析几何·射影几何·微分几何·欧几里得几何
toolhow1 小时前
SelfAttenion自注意力机制
pytorch·python·深度学习
智航GIS1 小时前
6.2 while循环
java·前端·python
2201_757830871 小时前
AOP核心概念
java·前端·数据库