> 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-scraper.md).

# AI-Scraper

## 概述

[**AI-Scraper**](https://aistudio.oxylabs.io/apps/scrape) 是一款抓取工具，可从单个网页提取数据。它会基于自然语言提示识别并解析相关信息，然后以以下任一形式返回结果： **JSON** （用于自动化和 API）或 **Markdown** 格式（适合可读输出和 AI 工作流）。

这款 AI-Scraper 消除了对 CSS/XPath 选择器或自定义解析器的需求，因此可以与各种自动化流水线无缝集成。 **自动生成 schema** 以及灵活的输出格式，为用户提供了一种轻松提取干净、结构化数据的方式，而无需维护解析逻辑。

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

## 主要功能

* **基于自然语言提示的提取** – 用通俗英文描述你的需求，抓取代理将获取相关信息。
* **多种输出格式** – 结构化工作流选择 JSON，或用于可读结果和 AI 工作流的 Markdown。
* **自动生成 schema** – 可从提示自动生成 schema，也可手动定义，以便进行精确的 JSON 解析。
* **适用于任何公开网页** – 可从电商、新闻、博客或任何其他可访问来源提取数据。

## 工作原理

要使用 AI-Scraper 抓取网页，请按以下步骤操作：

1. **提供要抓取的网页 URL** 。
2. **描述要提取的数据** ，使用自然语言（例如：“获取所有商品名称和价格”）。
3. **选择输出格式** – 结构化 JSON 或 Markdown。
4. **（可选）定义 schema** – 让 AI-Scraper 自动生成，或提供你自己的 OpenAPI schema，以获得你所需的精确结构。

### 安装

开始之前，请确保你可以访问 AI Studio API key（或 [获取免费试用](https://aistudio.oxylabs.io/register) 含 1000 点数）并且已安装 `Python v3.10` 或更高版本。您可以安装 `oxylabs-ai-studio` 软件包，使用 pip：

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

### 代码示例（Python）

以下示例展示了如何使用 `AiScraper` 从示例页面提取数据。

```python
from oxylabs_ai_studio.apps.ai_scraper import AiScraper
import json

# Initialize the AI Scraper with your API key
scraper = AiScraper(api_key="YOUR_API_KEY")

# 从自然语言自动生成 schema
schema = scraper.generate_schema(prompt="want to parse developer, platform, type, price game title, and genre (array)")
print(f"Generated schema: {schema}")

# Scrape a webpage and extract structured data
url = "https://sandbox.oxylabs.io/products/3"
result = scraper.scrape(
    url=url,
    output_format="json",
    schema=schema,
    render_javascript=False,
    geo_location="US",
)
# Print the scrape output as JSON
print("Results:")
print(json.dumps(result.data, indent=2))
```

在我们的文档中了解更多关于 AI-Scraper 和 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                       | –          |
| `output_format`                                    | 输出格式（`json`, `markdown`)         | `markdown` |
| `schema`                                           | 用于结构化提取的 OpenAPI schema（JSON 必需） | –          |
| `render_javascript`                                | 启用渲染 JavaScript                  | `False`    |
| `geo_location`                                     | ISO2 格式的代理位置                     | –          |

&#x20;    – 必填参数

### 输出示例

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

以下是其 JSON 输出示例：

```json
{
  "games": [
    {
      "developer": "Nintendo EAD Tokyo",
      "platform": "wii",
      "type": "singleplayer",
      "price": 91.99,
      "title": "Super Mario Galaxy 2",
      "genre": [
        "Action",
        "Platformer"
      ]
    },
    {
      "developer": "Eidos Interactive",
      "platform": "wii",
      "type": null,
      "price": 80.99,
      "title": "Death Jr.: Root of Evil",
      "genre": [
        "Action",
        "Platformer",
        "3D"
      ]
    }
}
```

或者，你可以设置 `output_format`  到 `markdown` 以接收 Markdown 格式的结果，而不是 JSON。

## 实际用例

AI-Scraper 可用于多种数据收集任务：

1. **提取产品详情** – 从电商网站收集商品名称、描述和价格。
2. **解析新闻文章** – 获取文章标题、日期、作者和正文。
3. **抓取价格页面** – 为竞品研究或市场研究收集结构化价格信息。
4. **提取职位信息** – 从招聘门户获取职位名称、地点、薪资和发布时间。

<br>


---

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