# AI-Search

## 概览

该 [**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 密钥访问权限（或者 [获得免费试用](https://aistudio.oxylabs.io/register) ，并且 **1,000 credits**）以及 `Python 3.10+` 已安装。你可以安装 `oxylabs-ai-studio` 包：

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

### 代码示例（Python）

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

```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)

# 或者进行快速搜索
result = search.instant_search(
    query=query,
    limit=10,
)
print(result.data)
```

在我们的文档中了解更多关于 AI-Search 和 Oxylabs AI Studio Python SDK 的信息 [PyPI repository](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;">`查询`</mark> | 要搜索的内容               | –       |
| `limit`                                           | 返回结果的最大数量（最大值：50）    | 10      |
| `render_javascript`                               | 启用 JavaScript 渲染     | `False` |
| `return_content`                                  | 是否在结果中返回 Markdown 内容 | `True`  |
| `geo_location`                                    | ISO2 格式的代理位置         | –       |

&#x20;    – 必填参数

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

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

即时搜索支持的参数：

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

&#x20;    – 必填参数

### 输出示例

```python
[
  {
    "url": "https://www.spendwithpennies.com/easy-homemade-lasagna/",
    "title": "简单自制千层面食谱 - Spend With Pennies",
    "description": "评分 5.0（3,349）· 1 小时 45 分钟 这是一道最棒的千层面食谱！意大利面、简单的肉酱和 ricotta 奶酪层层叠加，最后再撒上更多奶酪后烘烤。",
    "content": null
  },
  {
    "url": "https://www.simplyrecipes.com/recipes/lasagna/",
    "title": "最佳自制千层面 - Simply Recipes",
    "description": "评分 4.9（115）· 1 小时 45 分钟 这道经典千层面食谱以简单的肉酱为基础。将酱汁与面片和奶酪层层叠放，然后烘烤至冒泡！",
    "content": null
  },
  {
    "url": "https://www.seriouseats.com/12-lasagna-recipes-11808722",
    "title": "12 道必试的千层面食谱，带有酥脆边缘和浓郁拉丝...",
    "description": "无论你偏爱像博洛尼亚肉酱千层面这样的肉类经典款，还是丰盛奶油素食菠菜千层面，我们都为你整理了最喜爱的...",
    "content": null
  },
  {
    "url": "https://bakerbynature.com/the-best-homemade-lasagna-recipe/",
    "title": "最佳简单自制千层面食谱 - Baker by Nature",
    "description": "评分 5.0（71）· 2 小时 45 分钟 2025 年 12 月 12 日 · 这就是你此生所需的唯一一份千层面食谱……从完美煮熟的面片，到浓郁番茄酱和层层奶酪。",
    "content": null
  },
  {
    "url": "https://www.allrecipes.com/recipe/23600/worlds-best-lasagna/",
    "title": "世界最佳千层面食谱（含视频）- Allrecipes",
    "description": "评分 4.8（20,950）· 3 小时 15 分钟 2026 年 2 月 5 日 · 这道来自 John Chandler 的千层面食谱是我们最受欢迎的食谱！配有香肠、碎牛肉、罗勒和 3 种奶酪，名副其实...",
    "content": null
  }
]
```

## 实际使用场景

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

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


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
