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
相关推荐
C_心欲无痕4 小时前
前端实现水印的两种方式:SVG 与 Canvas
前端·安全·水印
梨子串桃子_6 小时前
推荐系统学习笔记 | PyTorch学习笔记
pytorch·笔记·python·学习·算法
尾善爱看海7 小时前
不常用的浏览器 API —— Web Speech
前端
美酒没故事°8 小时前
vue3拖拽+粘贴的综合上传器
前端·javascript·typescript
文言一心8 小时前
LINUX离线升级 Python 至 3.11.9 操作手册
linux·运维·python
诗词在线8 小时前
中国古代诗词名句按主题分类有哪些?(爱国 / 思乡 / 送别)
人工智能·python·分类·数据挖掘
高锰酸钾_8 小时前
机器学习-L1正则化和L2正则化解决过拟合问题
人工智能·python·机器学习
天天睡大觉8 小时前
Python学习11
网络·python·学习
智航GIS8 小时前
11.11 Pandas性能革命:向量化操作与内存优化实战指南
python·pandas