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
相关推荐
jingfeng5144 分钟前
C++ STL-string类底层实现
前端·c++·算法
cyforkk37 分钟前
Hexo 双分支部署指南:从原理到 Netlify 实战
前端
小小愿望41 分钟前
前端读取与导出XLSX文件实战指南(React+Ant Design)
前端
小小愿望1 小时前
JavaScript生成随机数的全面指南:别再只会用Math.random()了!
前端
用户847181054191 小时前
wps加载项ribbon.js 与 ribbon.xml 的交互
前端
Jackson__1 小时前
RAG究竟是什么?一文搞懂大模型的记忆增强术
前端
雲墨款哥1 小时前
JS算法练习-Day10-判断单调数列
前端·javascript·算法
前端市界1 小时前
前端视角: PyQt6+Vue3 跨界开发实战
前端·qt·pyqt
阅文作家助手开发团队_山神1 小时前
第四章:Flutter自定义Engine本地依赖与打包流程
前端·flutter
JuneXcy1 小时前
11.web api 2
前端·javascript·html