> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# Hyperbrowser 浏览器代理集成

> 使用 LangChain Python 与 Hyperbrowser 浏览器代理工具集成。

[Hyperbrowser website](https://hyperbrowser.ai) 是一个用于运行浏览器代理并扩展无头浏览器的平台。它允许您大规模启动和管理浏览器会话，并提供易于使用的解决方案以满足任何网页抓取需求，例如抓取单个页面或爬取整个站点。

主要功能：

* 即时扩展性 - 无需基础设施烦恼，数秒内启动数百个浏览器会话
* 简单集成 - 与 Puppeteer 和 Playwright 等流行工具无缝协作
* 强大的 API - 易于使用的 API，可抓取/爬取任何站点，以及更多功能
* 绕过反机器人措施 - 内置隐身模式、广告拦截、自动验证码解决和轮换代理

本指南提供了开始使用 Hyperbrowser 工具的快速概述。

有关 Hyperbrowser 的更多信息，请访问 [Hyperbrowser website](https://hyperbrowser.ai) 或如果您想查看文档，可以访问 [Hyperbrowser docs](https://docs.hyperbrowser.ai)。

## 浏览器代理

Hyperbrowser 提供强大的浏览器代理工具，使 AI 模型能够以编程方式与 Web 浏览器交互。这些浏览器代理可以导航网站、填写表单、点击按钮、提取数据并执行复杂的 Web 自动化任务。

浏览器代理特别适用于：

* 从复杂网站进行网页抓取和数据提取
* 自动化重复的 Web 任务
* 与需要身份验证的 Web 应用程序交互
* 跨多个网站进行研究
* 测试 Web 应用程序

Hyperbrowser 提供三种类型的浏览器代理工具：

* **Browser Use Tool**：通用浏览器自动化工具
* **OpenAI CUA Tool**：与 OpenAI 计算机使用代理集成
* **Claude Computer Use Tool**：与 Anthropic 的 Claude 用于计算机使用集成

## 概述

### 集成详情

| 工具                       | 包                      |  本地 | 可序列化 | JS 支持 |
| :----------------------- | :--------------------- | :-: | :--: | :---: |
| Browser Use Tool         | langchain-hyperbrowser |  ❌  |   ❌  |   ❌   |
| OpenAI CUA Tool          | langchain-hyperbrowser |  ❌  |   ❌  |   ❌   |
| Claude Computer Use Tool | langchain-hyperbrowser |  ❌  |   ❌  |   ❌   |

## 设置

要访问 Hyperbrowser 工具，您需要安装 `langchain-hyperbrowser` 集成包，并创建 Hyperbrowser 账户获取 API 密钥。

### 凭据

前往 [Hyperbrowser](https://app.hyperbrowser.ai/) 注册并生成 API 密钥。完成后设置 HYPERBROWSER\_API\_KEY 环境变量：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export HYPERBROWSER_API_KEY=<your-api-key>
```

### 安装

安装 **langchain-hyperbrowser**。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU langchain-hyperbrowser
```

## 实例化

### 浏览器使用工具

`HyperbrowserBrowserUseTool` 是一个使用浏览器代理（特别是 Browser-Use 代理）执行 Web 自动化任务的工具。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_hyperbrowser import HyperbrowserBrowserUseTool
tool = HyperbrowserBrowserUseTool()
```

### OpenAI CUA 工具

`HyperbrowserOpenAICUATool` 是一个专用工具，通过 Hyperbrowser 利用 OpenAI 计算机使用代理 (CUA) 功能。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_hyperbrowser import HyperbrowserOpenAICUATool
tool = HyperbrowserOpenAICUATool()
```

### Claude 计算机使用工具

`HyperbrowserClaudeComputerUseTool` 是一个专用工具，通过 Hyperbrowser 利用 Claude 的计算机使用功能。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_hyperbrowser import HyperbrowserClaudeComputerUseTool
tool = HyperbrowserClaudeComputerUseTool()
```

## 调用

### 基本用法

#### 浏览器使用工具

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_hyperbrowser import HyperbrowserBrowserUseTool

tool = HyperbrowserBrowserUseTool()
result = tool.run({"task": "Go to Hacker News and summarize the top 5 posts right now"})
print(result)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{'data': 'The top 5 posts on Hacker News right now are:\n1. Stop Syncing Everything - https://sqlsync.dev/posts/stop-syncing-everything/\n2. Move fast, break things: A review of Abundance by Ezra Klein and Derek Thompson - https://networked.substack.com/p/move-fast-and-break-things\n3. DEDA – Tracking Dots Extraction, Decoding and Anonymisation Toolkit - https://github.com/dfd-tud/deda\n4. Electron band structure in germanium, my ass (2001) - https://pages.cs.wisc.edu/~kovar/hall.html\n5. Show HN: I vibecoded a 35k LoC recipe app - https://www.recipeninja.ai', 'error': None}
```

#### OpenAI CUA 工具

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_hyperbrowser import HyperbrowserOpenAICUATool

tool = HyperbrowserOpenAICUATool()
result = tool.run(
    {"task": "Go to Hacker News and get me the title of the top 5 posts right now"}
)
print(result)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{'data': 'Here are the titles of the top 5 posts on Hacker News right now:\n\n1. "DEDA – Tracking Dots Extraction, Decoding and Anonymisation Toolkit"\n2. "A man powers home for eight years using a thousand old laptop batteries"\n3. "Electron band structure in Germanium, my ass"\n4. "Bletchley code breaker Betty Webb dies aged 101"\n5. "Show HN: Zig Topological Sort Library for Parallel Processing"', 'error': None}
```

#### Claude 计算机使用工具

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_hyperbrowser import HyperbrowserClaudeComputerUseTool

tool = HyperbrowserClaudeComputerUseTool()
result = tool.run({"task": "Go to Hacker News and summarize the top 5 posts right now"})
print(result)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{'data': "Now I'll summarize the top 5 posts on Hacker News as of April 1, 2025:\n\n### Top 5 Hacker News Posts Summary\n\n1. **A man powers home for eight years using a thousand old laptop batteries** (techoreon.com)\n   - 267 points, posted 5 hours ago\n   - An innovative DIY project where someone managed to power their home using recycled laptop batteries for an extended period.\n\n2. **Electron band structure in germanium, my ass** (wisc.edu)\n   - 611 points, posted 8 hours ago\n   - Academic or technical discussion about electron band structure in germanium, possibly with a controversial or humorous take given the title.\n\n3. **Bletchley code breaker Betty Webb dies aged 101** (bbc.com)\n   - 575 points, posted 8 hours ago\n   - Obituary for Betty Webb, who worked as a code breaker at Bletchley Park during WWII, passing away at the age of 101.\n\n4. **Show HN: Zig Topological Sort Library for Parallel Processing** (github.com/williamw520)\n   - 55 points, posted 3 hours ago\n   - A developer sharing a library written in Zig programming language for topological sorting that supports parallel processing.\n\n5. **The Myst Graph: A New Perspective on Myst** (githr.com)\n   - 107 points, posted 5 hours ago\n   - An article presenting a new analysis or visualization of the classic video game Myst, likely using graph theory.\n\nThese are the top 5 posts currently trending on Hacker News as of April 1, 2025.", 'error': None}
```

### 使用自定义会话选项

所有工具都支持自定义会话选项：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
result = tool.run(
    {
        "task": "Go to npmjs.com, and tell me when react package was last updated.",
        "session_options": {
            "session_options": {"use_proxy": True, "accept_cookies": True}
        },
    }
)
print(result)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{'data': 'I have found that the react package was last published 11 hours ago. This is the most recently updated package I could find.', 'error': None}
```

### 异步用法

所有工具都支持异步用法：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
async def browse_website():
    tool = HyperbrowserBrowserUseTool()
    result = await tool.arun(
        {
            "task": "Go to npmjs.com, click the first visible package, and tell me when it was updated"
        }
    )
    return result


result = await browse_website()
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{'data': 'The page displays information about the "Example Domain," stating that it is used for illustrative purposes and can be utilized without permission. There\'s a link to "More information..." but no specific contact details are provided.', 'error': None}
```

## 在代理中使用

以下是如何在代理中使用任何 Hyperbrowser 工具的方法：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_hyperbrowser import browser_use_tool
from langchain_openai import ChatOpenAI
from langchain.agents import create_agent


model = ChatOpenAI(temperature=0)

# You can use any of the three tools here
browser_use_tool = HyperbrowserBrowserUseTool()
agent = create_agent(model, [browser_use_tool])

user_input = "Go to npmjs.com, and tell me when react package was last updated."
for step in agent.stream(
    {"messages": user_input},
    stream_mode="values",
):
    step["messages"][-1].pretty_print()
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
================================ Human Message =================================

Go to npmjs.com, and tell me when react package was last updated.
================================== Ai Message ==================================
Tool Calls:
  hyperbrowser_browser_use (call_pkAaDjn6kKH9yT3rHDb4hmET)
 Call ID: call_pkAaDjn6kKH9yT3rHDb4hmET
  Args:
    task: Go to npmjs.com and find the last updated date of the React package.
    session_options: None
================================= Tool Message =================================
Name: hyperbrowser_browser_use

{"data": "The last updated date of the React package is a day ago.", "error": null}
================================== Ai Message ==================================

The React package was last updated a day ago.
```

## 配置选项

Claude 计算机使用、OpenAI CUA 和浏览器使用具有以下可用参数：

* `task`：使用代理执行的任务
* `max_steps`：代理完成任务可采取的最大交互步骤数
* `session_options`：浏览器会话配置

更多详细信息，请参阅相应的 API 参考：

* [Browser Use API Reference](https://docs.hyperbrowser.ai/reference/api-reference/agents/browser-use)
* [OpenAI CUA API Reference](https://docs.hyperbrowser.ai/reference/api-reference/agents/openai-cua)
* [Claude Computer Use API Reference](https://docs.hyperbrowser.ai/reference/api-reference/agents/claude-computer-use)

***

## API 参考

* [GitHub](https://github.com/hyperbrowserai/langchain-hyperbrowser/)
* [PyPI](https://pypi.org/project/langchain-hyperbrowser/)
* [Hyperbrowser Docs](https://docs.hyperbrowser.ai/)

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\python\integrations\tools\hyperbrowser_browser_agent_tools.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
