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蜂几秒前
CSRF Token:网络应用安全的关键防线——深度解析与实战指南
前端·安全·csrf
喜乐boy12 分钟前
CV系列——Conda + PyTorch + CUDA + cuDNN + Python 环境无脑安装速查笔记[2025.12]
pytorch·python·conda·cuda·cv
@游子18 分钟前
Python学习笔记-Day6
笔记·python·学习
电饭叔19 分钟前
Luhn算法与信用卡识别完善《python语言程序设计》2018版--第8章14题利用字符串输入作为一个信用卡号之三
android·python·算法
IT_陈寒19 分钟前
Redis 性能骤降50%?这5个隐藏配置陷阱你可能从未注意过
前端·人工智能·后端
躺着听Jay20 分钟前
【1267 - Illegal mix of collations 】mysql报错解决记录
java·linux·前端
月光技术杂谈21 分钟前
基于Python+Selenium的淘宝商品信息智能采集实践:从浏览器控制到反爬应对
爬虫·python·selenium·自动化·web·电商·淘宝
HsuHeinrich25 分钟前
利用表格探索宜居城市
python·数据可视化
过尽漉雪千山28 分钟前
Anaconda的虚拟环境下使用清华源镜像安装Pytorch
人工智能·pytorch·python·深度学习·机器学习
碧海银沙音频科技研究院30 分钟前
CLIP(对比语言-图像预训练)在长尾图像分类应用
python·深度学习·分类