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
相关推荐
CappuccinoRose12 分钟前
前端开发交互体系 - 汇总篇
开发语言·前端·javascript·css·html·交互
天天鸭28 分钟前
前端转全栈,要学会后端看项目的思维
前端·后端·ai编程
tryCbest30 分钟前
Python 爬虫从入门到实战(二):进阶篇——反爬对抗、并发与动态页面
开发语言·爬虫·python
oil欧哟30 分钟前
AI Agent 常用操作入门:独立目录、Plan 模式与跨话题交接指南
前端
VIP_CQCRE31 分钟前
GPT Image 2.6 动态表情交付别只发预览:GIF 文件校验、哈希清单与下载排错
图像处理·人工智能·python·gif
2601_9679873736 分钟前
使用 NumPy 和 Python 实现梯度下降
python·机器学习·线性回归·numpy·梯度下降
孟陬42 分钟前
Foobar 技术周刊 #161:AI 录屏员工屏幕训练 SOP,被当做「动物园的猴子」是否触犯隐私?
前端·后端·程序员
1-1=01 小时前
Vue 混入(Mixin)和 2.插件 (Plugins)
前端·vue.js
BD_Marathon1 小时前
Jupyter魔法命令
ide·python·jupyter
-梅1 小时前
linux(番外)线程,锁,条件变量封装;日志与线程池
linux·c语言·前端·c++