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
相关推荐
寰天柚子1 天前
Java并发编程中的线程安全问题与解决方案全解析
java·开发语言·python
2503_928411561 天前
项目中的一些问题(补充)
人工智能·python·tensorflow
superman超哥1 天前
仓颉语言中锁的实现机制深度剖析与并发实践
c语言·开发语言·c++·python·仓颉
vv_Ⅸ1 天前
打卡day42
python
快乐肚皮1 天前
一文了解XSS攻击:分类、原理与全方位防御方案
java·前端·xss
保护我方头发丶1 天前
ESP-wifi-蓝牙
前端·javascript·数据库
想学后端的前端工程师1 天前
【Flutter跨平台开发实战指南:从零到上线-web技术栈】
前端·flutter
Lvan的前端笔记1 天前
python:深入理解 Python 的 `__name__ == “__main__“` 与双下划线(dunder)机制
开发语言·python
老王Bingo1 天前
Qwen Code + Chrome DevTools MCP,让爬虫、数据采集、自动化测试效率提升 100 倍
前端·爬虫·chrome devtools
董世昌411 天前
什么是扩展运算符?有什么使用场景?
开发语言·前端·javascript