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

# AI-Search

了解如何使用 AI 搜索网页。用简单英语描述你的需求，让工具替你完成搜索。

## 概述

该 [**AI-Search**](https://aistudio.oxylabs.io/apps/search) 应用由 [**Oxylabs AI Studio**](https://aistudio.oxylabs.io/) 是一款网页搜索工具，允许开发者检索搜索结果，可选择性地抓取它们，并轻松处理由 JavaScript 渲染的内容。它旨在充当智能搜索代理，将相关信息直接提取到你的 Python 应用中，从而简化这一过程。

无论你需要简单的 URL 列表还是深度内容提取，AI Search 都能消除从头构建自定义搜索抓取器的复杂性。

## 主要功能

* **用通俗英语查询网页：** 只需用自然语言提供你的搜索查询，让代理完成繁重工作。
* **控制搜索结果数量：** 轻松精确地定义你要检索的结果数量。
* **结果页可选内容抓取：** 自动从返回的搜索结果中抓取并提取内容片段。
* **用于动态内容的 Python 渲染：** 启用渲染，可无缝处理并提取来自大量 JavaScript 的网站的数据。

## 工作原理

要使用搜索代理，请按以下简单步骤操作：

1. **输入搜索查询** 你要查找的内容。
2. **设置所需的结果数量** 以限制或扩大搜索范围。
3. **切换内容抓取和 JS 渲染** 依据你是否需要深度内容提取，还是只需要 URL 和标题。

### 安装

开始前，请确保你有 API key（或 [获取免费试用](https://aistudio.oxylabs.io/register) 配合 **1,000 积分**）以及 `Python 3.10+` 已安装。你可以安装 `oxylabs-ai-studio` 包，使用 pip：

```bash
pip install oxylabs-ai-studio
```

### 代码示例（Python）

以下示例演示如何使用 `AI-Search` 代理进行数据检索场景。

```python
from oxylabs_ai_studio.apps.ai_search import AiSearch

search = AiSearch(api_key="<API_KEY>")

query = "lasagna recipes"
result = search.search(
    query=query,
    limit=5,
    render_javascript=False,
    return_content=True,
)
print(result.data)

# Or for fast search
result = search.instant_search(
    query=query,
    limit=10,
)
print(result.data)
```

了解更多关于 AI-Search 和 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;">`query`</mark> | 要搜索的内容               | –       |
| `limit`                                              | 返回的搜索结果最大数量（最大值：50）  | 10      |
| `render_javascript`                                  | 启用 JavaScript 渲染     | `False` |
| `return_content`                                     | 是否在结果中返回 Markdown 内容 | `True`  |
| `geo_location`                                       | ISO2 格式的代理位置         | –       |

– 必填参数

**注意：** 当 `limit <= 10` 和 `return_content=False`，搜索将自动使用即时端点（`/search/instant`），它会立即返回结果，无需轮询，从而提供更快的响应时间。

{% hint style="info" %}
**注意：** 当 `limit <= 10` 和 `return_content=False`，搜索将自动使用即时端点（`/search/instant`），它会立即返回结果，无需轮询，从而提供更快的响应时间。
{% endhint %}

即时搜索支持的参数：

| 参数                                                   | 描述                                                                                        | 默认值  |
| ---------------------------------------------------- | ----------------------------------------------------------------------------------------- | ---- |
| <mark style="background-color:green;">`query`</mark> | 要搜索的内容                                                                                    | –    |
| `limit`                                              | 返回的搜索结果最大数量（最大值： `10`)                                                                    | `10` |
| `geo_location`                                       | Google 对该位置的规范名称。查看更多 [这里](https://developers.google.com/google-ads/api/data/geotargets). | –    |

– 必填参数

### 输出示例

```python
[
  {
    "url": "https://www.spendwithpennies.com/easy-homemade-lasagna/",
    "title": "Easy Homemade Lasagna Recipe - Spend With Pennies",
    "description": "Rating 5.0 (3,349) · 1 hr 45 min This is the best LASAGNA RECIPE! Pasta, an easy meat sauce, and ricotta cheese are layered and then topped with more cheese before baking.",
    "content": null
  },
  {
    "url": "https://www.simplyrecipes.com/recipes/lasagna/",
    "title": "The Best Homemade Lasagna - Simply Recipes",
    "description": "Rating 4.9 (115) · 1 hr 45 min This classic lasagna recipe is made with an easy meat sauce as the base. Layer the sauce with noodles and cheese, then bake until bubbly!",
    "content": null
  },
  {
    "url": "https://www.seriouseats.com/12-lasagna-recipes-11808722",
    "title": "12 Must-Try Lasagna Recipes Featuring Crispy Edges and Gooey ...",
    "description": "Whether you have a taste for meaty classics like a lasagna alla Bolognese or an indulgent creamy vegetarian spinach lasagna, we've rounded up our favorite ...",
    "content": null
  },
  {
    "url": "https://bakerbynature.com/the-best-homemade-lasagna-recipe/",
    "title": "The Best Easy Homemade Lasagna Recipe - Baker by Nature",
    "description": "Rating 5.0 (71) · 2 hr 45 min Dec 12, 2025 · This is the ONLY lasagna recipe you'll ever need... from perfectly cooked noodles to rich tomato sauce and layers of cheese.",
    "content": null
  },
  {
    "url": "https://www.allrecipes.com/recipe/23600/worlds-best-lasagna/",
    "title": "World's Best Lasagna Recipe (with Video) - Allrecipes",
    "description": "Rating 4.8 (20,950) · 3 hr 15 min Feb 5, 2026 · This lasagna recipe from John Chandler is our most popular recipe! With sausage, ground beef, basil, and 3 types of cheese, it lives up to ...",
    "content": null
  }
]
```

## 实际使用场景

AI-Search 可应用于多种数据发现和收集任务：

1. **搜索某个主题的最新新闻或文章——** 快速收集最新信息、标题和摘要。
2. **发现图书、电影或产品——** 检索符合特定条件或评论的项目列表。
3. **研究竞争产品——** 查找并分析竞争对手的定价、功能和市场定位。
4. **从多个网站汇总行业更新——** 将相关的行业变化和趋势汇编为一个结构化信息流。


---

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