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
相关推荐
西门啐血3 小时前
Vue 缓存之坑,变量赋值方式和响应式数据
前端·vue.js·缓存
Zane19943 小时前
闭包到底"闭"住了什么?一文讲透 LEGB 规则与循环里的闭包陷阱
后端·python
涛涛ing3 小时前
2026 上半年,前端圈已经炸了五次
前端
hunterandroid3 小时前
Android 后台任务可靠性排查:从 WorkManager 观测到失败重试闭环
android·前端
skiyee3 小时前
🔥 oiyo & unibest = 又新又好的 uniapp 模板
前端·uni-app
xingren3 小时前
「眨眼」UI 特效 - 在 Winform/WPF/WinUI3/Avalonia/Web 的实现
前端
Lumi_Peak3 小时前
Claude思考了42秒,我的代码质量直接提升了一个档次
python·claude
颜进强3 小时前
前端看后端 13:什么是 Cookie 和 Session?
前端·后端
月月大王的3D日记3 小时前
Three.js 入门系列(7):让甜甜圈围着我转 —— 3D文字生成
前端·javascript
gitboyzcf3 小时前
mpegts.js解决Chrome无法播放7568×142分辨率报错 DOMException问题
前端·后端