> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/cn/ai-studio/ai-crawler.md).

# AI-Crawler

## 概述

[**AI-Crawler**](https://aistudio.oxylabs.io/apps/crawl) 是一款数据提取应用，使用先进的 AI 算法抓取给定域名。它会根据自然语言提示识别相关页面，并提取结构化 **JSON** 或 **Markdown** 输出数据。

这款低代码工具旨在简化复杂的数据获取任务，让开发者和数据科学家专注于分析，而不是构建和维护自定义网页爬虫。AI 网页爬虫提供高级过滤、基于 schema 的解析，以及与各种自动化流水线的无缝集成。

您可以预览该工具 [**此处**](https://aistudio.oxylabs.io/apps/crawl) 并通过我们的 Python/JavaScript SDK、MCP 服务器或我们的第三方集成之一将其集成到您的工作流中。

## 主要功能

* **从任意给定 URL 开始抓取：** 使用 AI Crawler 作为起点，从任何有效的网页地址开始数据提取。
* **自然语言提示：** 用通俗英文定义你的数据需求，抓取代理会解析提示以找到相关内容。
* **AI 辅助的 URL 选择：** AI 网页爬虫会智能地探索网站，识别并优先处理与你的提示最匹配的页面。
* **多种输出格式：** 可选择结构化 JSON 或 Markdown 输出，以便无缝集成到自动化或 AI 工作流中。
* **基于 schema 的解析：** 对于 JSON 输出，你可以用自然语言定义解析 schema，以确保提取的数据结构化并适合你的应用。

## 用法

要开始使用 AI Crawler，请按以下四步进行：

1. **提供起始 URL** 作为你希望网页爬虫探索的网站地址。
2. **描述内容** 使用自然语言提示告诉抓取代理你要检索的内容。
3. **选择输出格式。** 在结构化 JSON 或 Markdown 之间选择。
4. **如果使用 JSON 输出，** 请提供一个 schema，引导 AI 网页爬虫解析并结构化提取的数据。

### 安装

开始前，请确保你已拥有 API key（或 [获取免费试用](https://aistudio.oxylabs.io/register) 使用 **1,000 credits**）并已 `安装 Python 3.10+。你可以安装` 以下示例演示了如何使用 `oxylabs-ai-studio` 软件包，使用 pip：

```sh
pip install oxylabs-ai-studio
```

### 代码示例（Python）

下面的示例演示了如何使用 `AiCrawler` 执行常见的抓取任务。

```python
from oxylabs_ai_studio.apps.ai_crawler import AiCrawler
import json

# 使用你的 API key 初始化 AI Crawler
crawler = AiCrawler(api_key="your_api_key")

# 从自然语言自动生成 schema
schema = crawler.generate_schema(prompt="want to parse name, platform, price")
print(f"Generated schema: {schema}")

# 抓取网站并提取结构化数据
url = "https://sandbox.oxylabs.io/products"
result = crawler.crawl(
    url=url,
    user_prompt="Find all Halo games for Xbox",
    output_format="json",
    schema=schema,
    render_javascript=False,
    return_sources_limit=3,
    geo_location="US",
)

# 将抓取输出打印为 JSON
print("Results:")
print(json.dumps(result.data, indent=2))
```

在我们的 PyPI 存储库中了解有关 AI-Crawler 和 Oxylabs AI Studio Python SDK 的更多信息 [PyPI 存储库](https://pypi.org/project/oxylabs-ai-studio/)。您也可以查看我们的 [AI Studio JavaScript SDK](https://github.com/oxylabs/oxylabs-ai-studio-js) 指南，适用于 JS 用户。

### 请求参数

| 参数                                                         | 说明                               | 默认值        |
| ---------------------------------------------------------- | -------------------------------- | ---------- |
| <mark style="background-color:green;">`url`</mark>         | 要抓取的起始 URL                       | –          |
| <mark style="background-color:green;">`user_prompt`</mark> | 用于指导提取的自然语言提示                    | –          |
| `output_format`                                            | 输出格式（`json`, `markdown`)         | `markdown` |
| `schema`                                                   | 用于结构化提取的 OpenAPI schema（JSON 必需） | –          |
| `render_javascript`                                        | 启用渲染 JavaScript                  | `False`    |
| `return_sources_limit`                                     | 返回的最大来源数量                        | `25`       |
| `geo_location`                                             | ISO2 格式的代理位置                     | –          |

&#x20;    – 必填参数

#### 输出示例

`AI-Crawler` 可以返回已解析、可直接使用的输出，便于集成到你的应用中。

以下是其 JSON 输出示例：

```json
[
  {
    "data": {
      "items": [
        {
          "name": "Halo: Reach",
          "platform": "Xbox platform",
          "price": 84.99
        }
      ]
    },
    "src": "https://sandbox.oxylabs.io/products/141"
  },
  {
    "data": {
      "items": [
        {
          "name": "Halo 3",
          "platform": "Xbox platform",
          "price": 81.99
        }
      ]
    },
    "src": "https://sandbox.oxylabs.io/products/28"
  },
  {
    "data": {
      "items": [
        {
          "name": "Halo: Combat Evolved",
          "platform": "Xbox platform",
          "price": 87.99
        }
      ]
    },
    "src": "https://sandbox.oxylabs.io/products/6"
  }
]
```

或者，你也可以使用 `output_format=”markdown”` 来接收 Markdown 结果，而不是解析后的 JSON。

### 实际用例

AI-Crawler 是一款用途广泛的工具，适用于多种场景，包括：

1. **查找服务条款页面：** 快速定位整个域名下的法律和政策页面。
2. **收集定价页面：** 用于竞品分析或市场研究时收集价格详情。
3. **检索所有“About”页面：** 自动从网站列表中查找并提取公司信息。
4. **列出与 AI 相关的新闻文章：** 抓取新闻站点，收集并归档特定主题的文章。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers.oxylabs.io/products/cn/ai-studio/ai-crawler.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
