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
相关推荐
SunnyDays10112 分钟前
如何使用 Python 将 ODT 转换为 PDF:完整指南
python·odt转pdf
JarvanMo3 分钟前
深度解析:如何彻底终结 Flutter 异步操作中的 BuildContext 崩溃?
前端
wxr06168 分钟前
部署Spring Boot项目+mysql并允许前端本地访问
前端·spring boot·mysql·持续部署
智算菩萨11 分钟前
【Python自然语言处理】基于NLTK库的英文文本词频统计系统实现原理及应用
开发语言·python·自然语言处理
假装我不帅14 分钟前
jquery-validation使用
前端·javascript·jquery
Ashley_Amanda18 分钟前
Python 常见问题梳理
开发语言·windows·python
怕浪猫19 分钟前
React从入门到出门第六章 事件代理机制与原生事件协同
前端·javascript·react.js
比奇堡的猪猪21 分钟前
修改默认conda环境(在win中)
python·conda
小白学大数据21 分钟前
如何用 Selenium 解决新闻数据批量采集难题
selenium·测试工具
天府之绝22 分钟前
uniapp 中使用uview表单验证时,自定义扩展的表单,在改变时无法触发表单验证处理;
开发语言·前端·javascript·vue.js·uni-app