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
相关推荐
E_ICEBLUE9 小时前
Python 教程:如何快速在 PDF 中添加水印(文字、图片)
开发语言·python·pdf
我爱学习_zwj9 小时前
服务器接收用户注册信息教程
python
大连滚呢王9 小时前
Linux(麒麟)服务器离线安装单机Milvus向量库
linux·python·milvus·银河麒麟·milvus_cli
宋辰月9 小时前
学习react第三天
前端·学习·react.js
bug总结9 小时前
更新原生小程序封装(新增缓存订阅)完美解决
前端·缓存·小程序
m0_7381207210 小时前
网络安全编程——基于Python实现的SSH通信(Windows执行)
python·tcp/ip·安全·web安全·网络安全·ssh
5335ld10 小时前
后端给的post 方法但是要求传表单数据格式(没有{})
开发语言·前端·javascript·vue.js·ecmascript
二川bro10 小时前
第33节:程序化生成与无限地形算法
前端·算法·3d·threejs
QDKuz10 小时前
掌握Vue2转Vue3, Options API 转 Composition API
前端·javascript·vue.js
老前端的功夫10 小时前
前端Echarts性能优化:从卡顿到流畅的百万级数据可视化
前端·javascript