> ## Documentation Index
> Fetch the complete documentation index at: https://gologin.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 在 AI 智能体中使用 Web Unlocker

> 如何将 Gologin Web Unlocker 用作 AI 智能体和 LLM 流水线的网页抓取工具

Gologin Web Unlocker 是一个抓取 API，可为任意 URL 返回完整渲染后的 HTML。对于 AI 智能体来说，这意味着无需编排浏览器，就能稳定地访问网页——每个页面只需一次 HTTP 调用。

> [!TIP]
>
> **不想写代码？** 使用 [Web Access CLI](https://gologin.com/docs/zh/cli-tools/web-access.md) 或 [Scraping Skill](https://gologin.com/docs/zh/api-reference/ai-integrations/ai-skills.md)，即可让您的智能体开箱即用地获得抓取能力。

***

## 将页面内容输入 LLM

抓取页面后，将 HTML 交给模型进行信息提取、摘要或分析——无需编写任何解析逻辑。

### Python + Claude

```python theme={null}
import requests
import anthropic

html = requests.get(
    "https://parsing.webunlocker.gologin.com/v1/scrape",
    params={"url": "https://news.ycombinator.com"},
    headers={"apikey": "YOUR_API_KEY"}
).text

client = anthropic.Anthropic()
message = client.messages.create(
    model="claude-sonnet-4-5-20250514",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": f"Extract the top 5 story titles and URLs from this HTML:\n\n{html[:8000]}"
        }
    ]
)

print(message.content[0].text)
```

### JavaScript + Claude

```javascript theme={null}
import Anthropic from "@anthropic-ai/sdk";

const html = await fetch(
  "https://parsing.webunlocker.gologin.com/v1/scrape?url=" +
    encodeURIComponent("https://news.ycombinator.com"),
  { headers: { apikey: "YOUR_API_KEY" } }
).then((r) => r.text());

const client = new Anthropic();
const message = await client.messages.create({
  model: "claude-sonnet-4-5-20250514",
  max_tokens: 1024,
  messages: [
    {
      role: "user",
      content: `Extract the top 5 story titles and URLs from this HTML:\n\n${html.slice(0, 8000)}`,
    },
  ],
});

console.log(message.content[0].text);
```

***

## 为智能体提供抓取工具

定义一个由 Web Unlocker 驱动的 `scrape` 工具。智能体会自行决定何时获取页面，以及要抓取哪个 URL。

```python theme={null}
import requests
import anthropic

def scrape(url: str) -> str:
    """Fetch a URL and return its rendered HTML."""
    return requests.get(
        "https://parsing.webunlocker.gologin.com/v1/scrape",
        params={"url": url},
        headers={"apikey": "YOUR_API_KEY"}
    ).text

tools = [
    {
        "name": "scrape",
        "description": "Fetch the rendered HTML of any URL, including JavaScript-heavy and protected sites.",
        "input_schema": {
            "type": "object",
            "properties": {
                "url": {"type": "string", "description": "The URL to scrape"}
            },
            "required": ["url"]
        }
    }
]

client = anthropic.Anthropic()
messages = [
    {"role": "user", "content": "What is the current price of the iPhone 16 Pro on apple.com?"}
]

while True:
    response = client.messages.create(
        model="claude-sonnet-4-5-20250514",
        max_tokens=1024,
        tools=tools,
        messages=messages
    )

    if response.stop_reason == "end_turn":
        print(response.content[0].text)
        break

    tool_results = []
    for block in response.content:
        if block.type == "tool_use" and block.name == "scrape":
            html = scrape(block.input["url"])
            tool_results.append({
                "type": "tool_result",
                "tool_use_id": block.id,
                "content": html[:10000]
            })

    messages.append({"role": "assistant", "content": response.content})
    messages.append({"role": "user", "content": tool_results})
```

智能体会自行决定何时抓取以及获取哪个 URL。Web Unlocker 负责完成页面获取——包括 JavaScript 渲染、绕过反爬机制、代理轮换和验证码求解。

***

## 使用 Web Unlocker SDK

对于 TypeScript/Node.js 智能体，`gologin-webunlocker` SDK 提供了带类型的方法：

```ts theme={null}
import { WebUnlocker } from "gologin-webunlocker";

const client = new WebUnlocker({
  apiKey: process.env.GOLOGIN_WEBUNLOCKER_API_KEY!
});

// get structured metadata instead of raw HTML
const { data } = await client.scrapeJSON("https://example.com");
console.log(data.title, data.description, data.headings);

// get clean text for LLM context
const { text } = await client.scrapeText("https://example.com");

// batch scrape with concurrency control
const results = await client.batchScrape(
  ["https://example.com/1", "https://example.com/2", "https://example.com/3"],
  { concurrency: 3 }
);
```

所有方法请参阅 [Web Unlocker SDK 参考](https://gologin.com/docs/zh/scraping-api-sdk-and-cli.md)。

***

## 使用 CLI

对于需要调用 shell 命令的智能体（例如 Claude Code），CLI 是最简单的方式：

```bash theme={null}
# plain text — good for LLM context
gologin-web-access scrape-text https://example.com

# structured JSON — title, description, headings, links
gologin-web-access scrape-json https://example.com

# batch scrape — many pages at once
gologin-web-access batch-scrape url1 url2 url3 --format text --summary

# search the web
gologin-web-access search "best antidetect browser 2026" --limit 10

# extract structured data with a schema
gologin-web-access extract https://example.com --schema ./schema.json
```

所有命令请参阅 [Web Access CLI 参考](https://gologin.com/docs/zh/cli-tools/web-access.md)。

***

## 常见智能体模式

| 模式 | 实现方式 |
| - | - |
| 调研智能体 | 智能体调用 `scrape` 工具 → 阅读页面 → 综合整理结论 |
| 价格监控 | 定时对商品页面执行 `batch-scrape` → 与上一次结果对比 |
| 竞品情报 | 使用 `crawl` 爬取竞品网站 → 交给 LLM 分析 |
| 线索补全 | 使用 `scrape-json` 抓取公司页面 → 提取结构化数据 |
| 内容聚合 | `search` + `scrape-text` → 构建精选内容源 |

***

## 相关内容

* [什么是 Web Unlocker](https://gologin.com/docs/zh/what-is-web-unlocker.md) — 产品概述与定价
* [Web Unlocker SDK](https://gologin.com/docs/zh/scraping-api-sdk-and-cli.md) — TypeScript SDK 参考
* [Web Access CLI](https://gologin.com/docs/zh/cli-tools/web-access.md) — 统一 CLI
* [AI Skills](https://gologin.com/docs/zh/api-reference/ai-integrations/ai-skills.md) — 适用于 Claude Code 的即插即用技能


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.