> 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** 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 密钥（或 [获取免费试用](https://aistudio.oxylabs.io/register) （含 1000 credits），并且 `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")

# Generate a schema automatically from natural language
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 格式的代理位置                     | –          |

– 必填参数

### 输出示例

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.
