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
相关推荐
Misnice2 分钟前
Webpack、Vite、Rsbuild区别
前端·webpack·node.js
青茶3603 分钟前
php怎么实现订单接口状态轮询(二)
前端·php·接口
沈浩(种子思维作者)13 分钟前
系统要活起来就必须开放包容去中心化
人工智能·python·flask·量子计算
2301_7903009618 分钟前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
m0_7369191034 分钟前
用Pandas处理时间序列数据(Time Series)
jvm·数据库·python
getapi36 分钟前
实时音视频传输与屏幕共享(投屏)
python
大橙子额1 小时前
【解决报错】Cannot assign to read only property ‘exports‘ of object ‘#<Object>‘
前端·javascript·vue.js
java干货1 小时前
为什么 “File 10“ 排在 “File 2“ 前面?解决文件名排序的终极算法:自然排序
开发语言·python·算法
机器懒得学习1 小时前
智能股票分析系统
python·深度学习·金融
毕设源码-郭学长1 小时前
【开题答辩全过程】以 基于python的二手房数据分析与可视化为例,包含答辩的问题和答案
开发语言·python·数据分析