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

# /search

了解如何使用 Oxylabs Web API /search 端点搜索实时网页并收集排序结果。

该 `/v1/search` 端点会执行实时网页搜索并返回经过排名的自然搜索结果，包括标题、摘要、URL、排名元数据和相关查询。&#x20;

它可作为发现工具，用于识别权威网页，然后将目标 URL 传递给 [`/v1/scrape`](https://developers.oxylabs.io/products/cn/web-api/scrape.md) 端点以提取完整页面内容。

{% hint style="info" %}
`/v1/search` 及其子端点仅支持 **同步（实时）调用**.
{% endhint %}

## 请求示例

该端点接受 JSON 请求体，其中包含搜索 **查询**, **结果数量限制**和 **地理位置** 参数。

```bash
curl https://webapi.oxylabs.io/v1/search \
  -H "Authorization: Bearer $OXYLABS_WEB_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "query": "eu ai act compliance deadlines",
    "max_results": 3,
    "location": "DE"
  }'
```

### 请求参数

<table><thead><tr><th width="123">参数</th><th width="533">说明</th><th width="88">类型</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><code>query</code></mark></td><td>搜索关键词或短语（长度介于 <code>1</code> 和 <code>2,048</code> 个字符之间）。</td><td>字符串</td></tr><tr><td><code>max_results</code></td><td>要返回的自然搜索结果数量（介于 <code>1</code> 和 <code>20</code>之间）。默认值： <code>10</code></td><td>整数</td></tr><tr><td><code>location</code></td><td>ISO 3166-1 alpha-2 国家代码（例如 <code>DE</code>, <code>US</code>），用于执行本地化搜索。</td><td>字符串</td></tr></tbody></table>

&#x20;    – 必填参数。

{% hint style="warning" %}
未知或拼写错误的参数会被拒绝，并返回 HTTP `400 Bad Request` 状态码，而不会被忽略。
{% endhint %}

### 优化请求

<details>

<summary><strong><code>query</code></strong></summary>

建议使用人们会在搜索框中输入的内容。关键词形式的查询效果优于句子形式的查询：

<table><thead><tr><th width="373">使用以下内容替代</th><th>改用</th></tr></thead><tbody><tr><td>"你能告诉我《欧盟人工智能法案》的合规截止日期吗？"</td><td><code>eu ai act compliance deadlines</code></td></tr><tr><td>"我想知道 Figma 每个席位的费用是多少"</td><td><code>figma pricing per seat</code></td></tr></tbody></table>

每次请求只问一个问题。复合查询返回的结果往往无法很好地匹配其中任何一个问题。

</details>

<details>

<summary><strong><code>max_results</code></strong></summary>

该参数表示上限，而非目标值。匹配结果较少时，返回的结果也较少，并按相关性从高到低排序。

</details>

<details>

<summary><strong><code>location</code></strong></summary>

价格、可用性、语言和排名往往因国家/地区而异。

唯一接受的格式是 ISO 3166-1 alpha-2 代码（例如 `DE`, `US`）。格式正确但未分配给任何国家/地区的代码会被拒绝，并返回 `400` 错误代码。省略该参数会设置为 `default` 区域设置；仅当答案不受地理位置影响时，这才是最佳选择。

</details>

## 输出示例

{% code expandable="true" %}

```json
{
    "state": "done",
    "results": [
        {
            "title": "Implementation Timeline | EU Artificial Intelligence Act",
            "outline": [
                "Providers: Providers of GPAI models that have been placed on the market before this date need to be compliant with the AI Act by 2 August 2027. ... Member States: Deadline for Member States to report to the Commission on the status of the financial and human resources of the national competent ..."
            ],
            "url": "https://artificialintelligenceact.eu/implementation-timeline/",
            "metadata": {
                "position": 1
            }
        },
        {
            "title": "EU AI Act Timeline: Key Compliance Dates & Deadlines Explained",
            "outline": [
                "While the EU Commission is working with member states to build out the reporting and monitoring infrastructure of the AI Act until August 2025, companies have several key areas to focus on: establishing a risk management system, implementing data governance measures, drawing up technical ..."
            ],
            "url": "https://www.dataguard.com/eu-ai-act/timeline",
            "metadata": {
                "position": 2
            }
        },
        {
            "title": "Timeline for the Implementation of the EU AI Act | AI Act Service Desk",
            "outline": [
                "The EU’s AI Act legislation applies progressively, with a full roll-out of the main application milestones foreseen by 2 August 2028."
            ],
            "url": "https://ai-act-service-desk.ec.europa.eu/en/ai-act/timeline/timeline-implementation-eu-ai-act",
            "metadata": {
                "position": 3
            }
        }
    ],
    "related_questions": [],
    "related_searches": [],
    "params": {
        "query": "eu ai act compliance deadlines",
        "location": "DE",
        "max_results": 3
    },
    "metadata": {
        "timestamp": 1791289627,
        "request_id": "1791289625962078444"
    }
}
```

{% endcode %}

{% hint style="warning" %}
**`outline`** 只是有代表性的摘要。若要获取页面本身的实时数据， [请抓取该 URL](https://developers.oxylabs.io/products/cn/web-api/scrape.md).
{% endhint %}

### 输出字典

<table><thead><tr><th width="237">字段</th><th width="438.04296875">说明</th><th width="87.94140625">类型</th></tr></thead><tbody><tr><td><code>state</code></td><td><code>"done"</code> 表示成功。搜索遇到上游故障时会返回 <code>500</code> 并附带 <code>state: "faulted"</code> （请参阅 <a href="https://developers.oxylabs.io/products/cn/web-api/gu-zhang-pai-cha.md">错误代码</a>).</td><td>字符串</td></tr><tr><td><code>results</code></td><td>按排名排序的自然搜索结果，最佳结果排在最前。该字段始终存在，因此输出为空表示没有匹配项。</td><td>数组</td></tr><tr><td><code>results[].title</code></td><td>抓取的页面标题。</td><td>字符串</td></tr><tr><td><code>results[].outline[]</code></td><td>搜索引擎结果页（SERP）的结果摘要，可能会在句子中途截断。</td><td>字符串数组</td></tr><tr><td><code>results[].url</code></td><td>结果的绝对 URL。传递给 <a href="https://developers.oxylabs.io/products/cn/web-api/scrape.md"><code>/v1/scrape</code></a>.</td><td>字符串</td></tr><tr><td><code>results[].metadata.position</code></td><td>自然搜索结果在 SERP 中的位置，从 <code>1</code>.</td><td>整数</td></tr><tr><td><code>related_questions</code></td><td>“用户还会问”问题对象，包含 <code>question</code>, <code>title</code>和 <code>snippet</code> （如有）。</td><td>数组</td></tr><tr><td><code>related_searches</code></td><td>相关搜索查询，每项包含 <code>query</code>.</td><td>数组</td></tr><tr><td><code>params</code></td><td>执行参数，包括默认值。</td><td>对象</td></tr><tr><td><code>metadata.timestamp</code></td><td>以秒为单位的 Unix 时间戳。</td><td>整数</td></tr><tr><td><code>metadata.request_id</code></td><td>19 位请求标识符。 <strong>请在支持工单中附上此标识符。</strong></td><td>字符串</td></tr></tbody></table>

{% hint style="info" %}
`related_searches` 适用于扩展查询，尤其是在首次搜索结果较少时。它提供了覆盖范围更广的搜索措辞。
{% endhint %}

### 专用搜索端点

除常规网页搜索外，还提供专用搜索端点，路径为 `POST /v1/search/{collection}`。它们接受类似于 `query` 的参数，例如 `/v1/search`，但返回特定实体类型的结构化记录，而非按排名排序的网页：

```bash
curl https://webapi.oxylabs.io/v1/search/companies \
  -H "Authorization: Bearer $OXYLABS_WEB_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "query": "新能源领域的公司",
    "max_results": 3
  }'
```

<table><thead><tr><th width="163">端点</th><th width="469">返回内容</th><th width="133">输入</th></tr></thead><tbody><tr><td><a href="https://developers.oxylabs.io/products/cn/web-api/search/company.md"><code>/search/companies</code></a></td><td>公司资料：行业、总部、员工人数、收入、网站流量。</td><td>关键词 / 查询</td></tr></tbody></table>

{% hint style="info" %}
专用搜索端点有各自的参数和输出字段。重复使用某个端点的参数前，请先查看该端点的文档页面。 `/v1/search` 请求正文。
{% endhint %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.oxylabs.io/products/cn/web-api/search.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
