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

# Sử dụng Web Unlocker với AI Agent

> Cách sử dụng Gologin Web Unlocker làm công cụ thu thập dữ liệu cho AI agent và pipeline LLM

Gologin Web Unlocker là một API thu thập dữ liệu, trả về HTML đã được hiển thị đầy đủ cho bất kỳ URL nào. Với AI agent, điều này có nghĩa là truy cập web ổn định mà không cần điều phối trình duyệt — chỉ một lệnh gọi HTTP cho mỗi trang.

> [!TIP]
>
> **Không muốn viết code?** Hãy dùng [Web Access CLI](https://gologin.com/docs/vi/cli-tools/web-access.md) hoặc [Scraping Skill](https://gologin.com/docs/vi/api-reference/ai-integrations/ai-skills.md) để trang bị ngay cho agent của bạn khả năng thu thập dữ liệu.

***

## Đưa nội dung trang vào LLM

Thu thập một trang rồi chuyển HTML cho mô hình để trích xuất, tóm tắt hoặc phân tích — không cần viết logic phân tích cú pháp.

### 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);
```

***

## Cung cấp công cụ scrape cho agent

Hãy định nghĩa một công cụ `scrape` dựa trên Web Unlocker. Agent sẽ tự quyết định khi nào cần tải một trang và URL nào cần thu thập.

```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})
```

Agent tự quyết định khi nào cần thu thập và URL nào cần tải. Web Unlocker đảm nhận phần truy xuất dữ liệu — hiển thị JavaScript, vượt cơ chế chống bot, xoay vòng proxy và giải CAPTCHA.

***

## Sử dụng Web Unlocker SDK

Đối với các agent viết bằng TypeScript/Node.js, SDK `gologin-webunlocker` cung cấp các phương thức có định kiểu:

```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 }
);
```

Xem [tài liệu tham khảo Web Unlocker SDK](https://gologin.com/docs/vi/scraping-api-sdk-and-cli.md) để biết tất cả các phương thức.

***

## Sử dụng CLI

Đối với các agent gọi lệnh shell (như Claude Code), CLI là cách đơn giản nhất:

```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
```

Xem [tài liệu tham khảo Web Access CLI](https://gologin.com/docs/vi/cli-tools/web-access.md) để biết tất cả các lệnh.

***

## Các mẫu sử dụng phổ biến cho agent

| Mẫu sử dụng | Cách thực hiện |
| - | - |
| Agent nghiên cứu | Agent gọi công cụ `scrape` → đọc các trang → tổng hợp kết quả |
| Theo dõi giá | `batch-scrape` các trang sản phẩm theo lịch → so sánh với lần chạy trước |
| Tình báo cạnh tranh | `crawl` các trang web của đối thủ → đưa cho LLM phân tích |
| Làm giàu dữ liệu khách hàng tiềm năng | `scrape-json` các trang công ty → trích xuất dữ liệu có cấu trúc |
| Tổng hợp nội dung | `search` + `scrape-text` → xây dựng các nguồn cấp nội dung được chọn lọc |

***

## Liên quan

* [Web Unlocker là gì](https://gologin.com/docs/vi/what-is-web-unlocker.md) — tổng quan sản phẩm và bảng giá
* [Web Unlocker SDK](https://gologin.com/docs/vi/scraping-api-sdk-and-cli.md) — tài liệu tham khảo TypeScript SDK
* [Web Access CLI](https://gologin.com/docs/vi/cli-tools/web-access.md) — CLI hợp nhất
* [AI Skills](https://gologin.com/docs/vi/api-reference/ai-integrations/ai-skills.md) — các skill cắm là chạy dành cho Claude Code


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