> 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

了解如何从一个 URL 开始抓取网站，查找相关页面并提取数据——全部由你的自然语言提示引导。

## 概述

[**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 积分**）以及 `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

# Initialize the AI Crawler with your API key
crawler = AiCrawler(api_key="your_api_key")

# Generate a schema automatically from natural language
schema = crawler.generate_schema(prompt="want to parse name, platform, price")
print(f"Generated schema: {schema}")

# Crawl a website and extract structured data
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",
)

# Print the crawl output as JSON
print("Results:")
print(json.dumps(result.data, indent=2))
```

在我们的 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 格式的代理位置                     | –          |

– 必填参数

#### 输出示例

`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. **检索所有“关于”页面：** 从网站列表中自动查找并提取公司信息。
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.
