> ## 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.

# Web Unlocker 使用场景

Web Unlocker 是一个 Scraping API——您发送一个 URL，它就会返回完整渲染后的 HTML。本页介绍几种最常见的使用方式。

***

## 自行抓取页面

最简单的使用场景：您需要获取某个会拦截普通 HTTP 请求的网页内容。

### Python

```python theme={null}
import requests

response = requests.get(
    "https://parsing.webunlocker.gologin.com/v1/scrape",
    params={"url": "https://example.com/product/123"},
    headers={"apikey": "YOUR_API_KEY"}
)

html = response.text
print(html)
```

### JavaScript

```javascript theme={null}
const html = await fetch(
  "https://parsing.webunlocker.gologin.com/v1/scrape?url=" +
    encodeURIComponent("https://example.com/product/123"),
  { headers: { apikey: "YOUR_API_KEY" } }
).then((r) => r.text());

console.log(html);
```

无需启动浏览器，无需配置代理，也无需与 Cloudflare 对抗。一次调用，即可获得页面内容。

**适用于：**

* 查看竞争对手网站上的价格
* 获取招聘信息、评论或商品数据
* 监控页面变化
* 一次性的数据采集脚本

***

## 将内容输入 AI

Web Unlocker 返回的是原始 HTML。将它传给大语言模型（LLM），即可提取结构化数据、总结内容或回答与页面相关的问题，无需编写任何解析逻辑。

### Python + OpenAI

```python theme={null}
import requests
from openai import OpenAI

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

client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {
            "role": "user",
            "content": f"Extract the top 5 story titles and their URLs from this HTML:\n\n{html[:8000]}"
        }
    ]
)

print(response.choices[0].message.content)
```

### JavaScript + Anthropic

```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-opus-4-5",
  max_tokens: 1024,
  messages: [
    {
      role: "user",
      content: `Extract the top 5 story titles and their URLs from this HTML:\n\n${html.slice(0, 8000)}`,
    },
  ],
});

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

**适用于：**

* 无需编写解析器即可提取结构化数据（价格、名称、日期等）
* 总结文章或商品页面
* 对比多个页面并得出结论
* 构建由 AI 驱动的研究或监控工具

***

## 在 AI 智能体中使用

为您的 AI 智能体提供一个由 Web Unlocker 支持的 `scrape` 工具。这样，智能体就能自主浏览网页——获取页面、阅读内容并采取行动——而您无需编写任何浏览逻辑。

```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-opus-4-5",
        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 完成。

**适用于：**

* 能够自主浏览网页的研究型智能体
* 比价或优惠发现机器人
* 竞争情报流程
* 任何需要实时网页数据的智能体

***

## 一次抓取多个页面

并发发送请求，同时从多个 URL 采集数据。

```python theme={null}
import requests
from concurrent.futures import ThreadPoolExecutor

API_URL = "https://parsing.webunlocker.gologin.com/v1/scrape"
API_KEY = "YOUR_API_KEY"

urls = [
    "https://example.com/page/1",
    "https://example.com/page/2",
    "https://example.com/page/3",
]

def scrape(url):
    response = requests.get(
        API_URL,
        params={"url": url},
        headers={"apikey": API_KEY}
    )
    return url, response.text

with ThreadPoolExecutor(max_workers=5) as executor:
    results = list(executor.map(scrape, urls))

for url, html in results:
    print(f"{url}: {len(html)} chars")
```

**适用于：**

* 抓取整个商品目录或列表页面
* 为训练数据集进行批量数据采集
* 同时监控多个页面

***

## 小结

| 使用场景 | 您需要做什么 | 您将获得什么 |
| - | - | - |
| 抓取单个页面 | 使用 URL 参数发送 GET 请求 | 渲染后的 HTML |
| 输入 LLM | 抓取 → 传给模型 | 提取的数据或摘要 |
| AI 智能体工具 | 智能体按需调用 | 实时网页内容 |
| 批量抓取 | 并发请求 | 每个 URL 对应的 HTML |

***

## 通过命令行使用

完全无需编写代码——使用 Gologin Web Access CLI 即可完成常见的抓取工作流：

```bash theme={null}
npm install -g gologin-web-access
export GOLOGIN_WEB_UNLOCKER_API_KEY="wu_..."

# batch scrape multiple pages
gologin-web-access batch-scrape \
  https://example.com/page/1 \
  https://example.com/page/2 \
  https://example.com/page/3 \
  --format text --only-main-content --summary

# crawl a site
gologin-web-access crawl https://docs.example.com --format markdown --limit 50 --max-depth 2

# monitor page changes
gologin-web-access change-track https://example.com/pricing --format markdown

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

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

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

***

## 小结

| 使用场景 | 您需要做什么 | 您将获得什么 |
| - | - | - |
| 抓取单个页面 | 使用 URL 参数发送 GET 请求 | 渲染后的 HTML |
| 输入 LLM | 抓取 → 传给模型 | 提取的数据或摘要 |
| AI 智能体工具 | 智能体按需调用 | 实时网页内容 |
| 批量抓取 | 并发请求 | 每个 URL 对应的 HTML |
| 命令行工作流 | `gologin-web-access` 命令 | 文本、Markdown、JSON、批量结果 |

要发出您的第一个请求，请参阅[快速入门](https://gologin.com/docs/zh/web-unlocker-quick-start.md)。


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