browser-use/browser-use · 上手攻略

  • 仓库:browser-use/browser-use
  • 链接:https://github.com/browser-use/browser-use
  • 分类:ai
  • 作者:Jay
  • 更新:2026-07-11

这是什么

browser-use 是让 AI Agent 操作浏览器的 Python 库——AI 描述任务,浏览器替你完成:点按钮、填表单、滚动页面、抓取内容。2026 年 7 月 Stars 104k+,Odysseys 排行榜第一(87.4% 平均准确率),领先 OpenAI、Anthropic、Google、Microsoft 的同类产品。

有两种使用方式:CLI(给已有 Agent 如 Claude Code、OpenClaw 用,直接控制你的浏览器)和 Python 库(嵌入自己的软件,做规模化爬虫或自动化产品)。


解决什么问题

  • 网页自动化无需写爬虫:描述你要做什么,AI 自己操作 DOM,不再需要 XPath/CSS 选择器
  • 多步骤网页任务:填申请表、批量注册、跨网站数据汇总,AI 自己导航
  • AI Agent 的眼睛:给 Agent 提供真实网页交互能力,不只是读 HTML
  • 多 LLM 支持:一个 API Key(Browser Use Cloud)或自备 OpenAI/Anthropic/Google Key,都能用
  • Benchmark 第一:Odysseys 200 个长程网页任务中 87.4% 完成率,工程化程度高

快速安装

Python 库安装

# uv(推荐)
uv add browser-use

# pip
pip install browser-use

要求:Python 3.11+

安装浏览器驱动

# 方式 A:使用 browser-use skill 安装(配合 OpenClaw、Claude Code 等 Agent)
browser-use skill install

# 方式 B:手动安装 Playwright 浏览器
playwright install chromium

# 方式 C:参考 browser-harness 安装文档
# https://github.com/browser-use/browser-harness/blob/main/install.md

配置 API Key

# .env 文件
# 方式 1:Browser Use Cloud(推荐,接入其优化过的 bu-* 模型)
BROWSER_USE_API_KEY=your-key

# 方式 2:自备其他 provider key
# ANTHROPIC_API_KEY=sk-...
# GOOGLE_API_KEY=...
# OPENAI_API_KEY=sk-...

获取 Browser Use Cloud API Key:https://cloud.browser-use.com/new-api-key


核心用法

方式一:Python 库(推荐用于开发自动化产品)

import asyncio
from browser_use import Agent, ChatBrowserUse

async def main():
    agent = Agent(
        task="Find the number of stars of the browser-use repo",
        llm=ChatBrowserUse(model='openai/gpt-5.5'),
        # 也可用 bu-2.0(Browser Use 自优化模型):
        # llm=ChatBrowserUse(model='bu-2.0'),
        # 或直接用 provider 前缀:
        # llm=ChatBrowserUse(model='anthropic/claude-sonnet-4-6'),
    )
    history = await agent.run()

if __name__ == "__main__":
    asyncio.run(main())

支持的模型

模型 方式
openai/gpt-5.5 ChatBrowserUse
anthropic/claude-sonnet-4-6 ChatBrowserUse
google/gemini-3-pro ChatBrowserUse
bu-2.0 Browser Use 优化模型(默认推荐)

一个 BROWSER_USE_API_KEY 可覆盖所有 provider(OpenAI/Anthropic/Google),不需要各自独立 Key。

自定义工具扩展

from browser_use import Agent, ChatBrowserUse, Tools

tools = Tools()

@tools.action(description='Description of what this tool does.')
def my_custom_tool(param: str) -> str:
    return f"Result: {param}"

agent = Agent(
    task="Your task",
    llm=llm,
    tools=tools,
)

方式二:CLI(给已有 Agent 使用)

如果你在用 Claude Code、OpenClaw、Cursor、Codex 等 Agent,把下面这段发给它即可:

Install or upgrade browser-use to the latest stable version with uv using Python 3.12, run browser-use skill install to register the skill, and connect it to my browser. If setup or connection fails, follow https://github.com/browser-use/browser-harness/blob/main/install.md. Then tell my agent what you want done.

CLI 的典型任务示例: - "Upload this video to YouTube" - "Compare these three laptops and give me a table with prices" - "Fill in this job application with my resume"

调度/并行任务(Python 库)

适合爬虫、监控、QA 自动化:

# 批量任务并行
tasks = ["任务1描述", "任务2描述", "任务3描述"]
for task in tasks:
    agent = Agent(task=task, llm=llm)
    asyncio.run(agent.run())

典型适用场景

  1. 网页数据采集:不需要写爬虫规则,告诉 AI 采集什么,它自己导航翻页
  2. 批量填表:职位申请、参会报名等重复性表单操作
  3. UI 自动化 QA:自动跑网页端功能测试,截图记录结果
  4. 价格监控:监控竞品网站价格变化,自动告警
  5. 将浏览器能力接入 AI Agent:Claude Code/Cursor 等 Agent 不能操作网页?browser-use 补上这个缺口
  6. 金融数据抓取:抓取财报、招股书、宏观数据,自建分析素材库

坑与注意

  1. Python 3.11+ 强制:Python 3.10 及以下不支持
  2. Cloud Key vs 自备 Key:Browser Use Cloud 的 bu-* 模型做了专项优化,速度/准确率优于通用模型,建议先用 Cloud Key 测试效果再决定
  3. 反爬网站:Cloud 版本有代理轮换 + CAPTCHA 解决,自托管版本可能被检测
  4. stealth 程度:官方 Cloud 版有专门的 stealth 优化,开源自托管版本视具体网站而定
  5. 长任务可能超时:极长任务建议分段提交,避免单次 context 溢出
  6. 并发控制:大量并行任务时注意系统资源占用,每个 Agent 实例约一个浏览器实例
  7. /examples 目录:仓库的 examples/use-cases/ 目录下有多个参考代码(apply_to_job.py、buy_groceries.py 等),建议通读

与同类对比

工具 Stars 核心差异 优势 劣势
browser-use 104k AI 驱动 DOM 操作,Benchmark 第一 准确率高、多 LLM 支持、CLI+库双模式 需 Python 环境
Playwright MCP 微软官方 MCP server 成熟稳定、MCP 生态 非 AI 驱动,需要写代码
Selenium/Playwright 传统网页自动化 完全控制 需要写代码,非 AI
OpenAI computer-use OpenAI 官方浏览器 Agent 品牌背书 准确率低于 browser-use
Antrophic computer-use Claude 原生浏览器操作 Claude 推理强 价格贵

browser-use 核心优势:开源 + Benchmark 第一 + 多 LLM + CLI 零门槛接入。如果你已经有 Claude Code/OpenClaw 等 Agent,不想改代码,直接装 CLI 就能让它操作浏览器。


一句话推荐

不管你是想给现有 Agent 装上"浏览网页"的能力,还是想自己写网页自动化脚本,browser-use 是 2026 年这个方向上工程化最完善、benchmark 表现最好的开源选择。