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
相关推荐
zhengxianyi51510 分钟前
vue-cli build, vite build 生产部署刷新或弹窗404,页面空白修复方法
前端·javascript·vue.js·nginx·生产部署
Filotimo_12 分钟前
前端项目打包部署完整流程
前端
Savvy..13 分钟前
Day15 Talis 前端
前端
筱昕~呀21 分钟前
基于深度生成对抗网络的智能实时美妆设计
人工智能·python·生成对抗网络·mediapipe·beautygan
恋爱绝缘体125 分钟前
Vue.js 组件 - 自定义事件【1】
前端·javascript·vue.js
企业对冲系统官25 分钟前
期货与期权一体化平台风险收益评估方法与模型实现
运维·服务器·开发语言·数据库·python·自动化
梦65028 分钟前
JavaScript ES5 + ES6+ 字符串 (String) 所有方法大全
前端·javascript·es6
馨谙37 分钟前
面试题----用户,组,su,su-,sudo,sudo-,nologin shell
java·前端·数据库
cuckooman40 分钟前
uv设置国内源
python·pip·uv·镜像源
一见1 小时前
如何安装 dlib 和 OpenCV(不带 Python 绑定)
人工智能·python·opencv