> ## Documentation Index
> Fetch the complete documentation index at: https://help.decodo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# YouTube 搜索和搜索最大值

> 网页抓取 API YouTube 搜索模板

`youtube_search` 目标用于获取 YouTube 搜索的前 20 个结果，而 `youtube_search_max` 目标可以接收多达 700 个结果。可以使用下面列出的特定过滤参数来过滤结果。

<Note>
  ### 有用链接

  * [**实时**](https://help.decodo.com/docs/cn/web-scraping-api-real-time-requests) 和 [**异步**](https://help.decodo.com/docs/cn/web-scraping-api-asynchronous-requests) 集成方法可用于此模板
  * 不支持批量请求。
</Note>

## 输入参数

**常规参数：**

| 参数       | 类型     | 必需 | 描述                                                 |
| -------- | ------ | -- | -------------------------------------------------- |
| `target` | string | ✅  | 目标类型必须设置为 `youtube_search` 或 `youtube_search_max`。 |
| `query`  | string | ✅  | 搜索查询。                                              |

**搜索结果过滤参数：**

| 参数            | 类型     | 描述                                                                                                        |
| ------------- | ------ | --------------------------------------------------------------------------------------------------------- |
| `upload_date` | string | 轻松查找 YouTube 上的最新内容。<br />可用值：`today`、`last_hour`、`this_week`、`this_month`、`this_year`。                   |
| `type`        | string | 定义要搜索的媒体类型。可用值：`video`、`channel`、`playlist`、`movie`。                                                      |
| `duration`    | string | 媒体持续时间（分钟）。值 `<4`、`<20`、`4-20`                                                                            |
| `sort_by`     | string | 定义搜索结果的排序方式。可用值 `rating`、`relevance`、`view_count`、`upload_date`<br />默认情况下，YouTube 视频按 `Relevance`（相关性）排序 |

**按功能过滤：**

| 参数                 | 类型      | 描述                      |
| ------------------ | ------- | ----------------------- |
| `live`             | boolean | 返回当前在 YouTube 上直播的内容。   |
| `4k`               | boolean | 返回 4K 分辨率视频的结果。         |
| `hd`               | boolean | 返回高清视频。                 |
| `subtitles`        | boolean | 仅返回带有字幕的内容。             |
| `creative_commons` | boolean | 返回许可重复使用的内容。            |
| `360`              | boolean | 在结果中返回 360° 视频。         |
| `vr180`            | boolean | 返回 vr180 格式的结果。         |
| `3d`               | boolean | 返回带有 3D 视频的结果。          |
| `hdr`              | boolean | 返回高动态范围视频。              |
| `location`         | boolean | 根据位置返回地理标记的视频。          |
| `purchased`        | boolean | 返回用户在 YouTube 上购买或租用的视频 |

### 请求示例

<CodeGroup>
  ```shellscript cURL theme={null}
  curl --request 'POST' \
          --url 'https://scraper-api.decodo.com/v2/scrape' \
          --header 'Accept: application/json' \
          --header 'Authorization: Basic TOKEN VALUE' \
          --header 'Content-Type: application/json' \
          --data '
      {
        "target": "youtube_search",
        "query": "what is scraping"
      }
  '
  ```

  ```javascript Node theme={null}
  const scrape = async() => {
    const response = await fetch("https://scraper-api.decodo.com/v2/scrape", {
      method: "POST",
      body: JSON.stringify({
        "target": "youtube_search",
        "query": "what is scraping",
      }),
      headers: {
        "Content-Type": "application/json",
        "Authorization": "Basic TOKEN VALUE" // 使用您的授权令牌更新
      },
    }).catch(error => console.log(error));

    console.log(await response.json())
  }

  scrape()
  ```

  ```python Python theme={null}
  import requests
    
  url = "https://scraper-api.decodo.com/v2/scrape"
    
  payload = {
        "target": "youtube_search",
        "query": "what is scraping"
  }
    
  headers = {
      "accept": "application/json",
      "content-type": "application/json",
      "authorization": "Basic TOKEN VALUE" # 使用您的授权令牌更新
  }
    
  response = requests.post(url, json=payload, headers=headers)
    
  print(response.text)
  ```
</CodeGroup>

## 输出

作为输出，您将获得一个包含 YouTube 搜索结果的 `JSON` 文件。

#### 输出示例

<CodeGroup>
  ```json JSON expandable theme={null}
  {
    "results": [
        {
            "content": [
                {
                    "videoId": "Ct8Gxo8StBU",
                    "thumbnail": {
                        "thumbnails": [
                            {
                                "url": "https://i.ytimg.com/vi/Ct8Gxo8StBU/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLD8B9UPBGhqTE1qtbV5ANHrjlaJvQ",
                                "width": 360,
                                "height": 202
                            },
                            {
                                "url": "https://i.ytimg.com/vi/Ct8Gxo8StBU/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBD9wL_yUERHg4A2amoScSJa1SDeQ",
                                "width": 720,
                                "height": 404
                            }
                        ]
                    },
                    "title": {
                        "runs": [
                            {
                                "text": "What is Web Scraping and What is it Used For? | Definition and Examples EXPLAINED"
                            }
                        ],
                        "accessibility": {
                            "accessibilityData": {
                                "label": "What is Web Scraping and What is it Used For? | Definition and Examples EXPLAINED 3 minutes, 40 seconds"
                            }
                        }
                    },
                    "longBylineText": {
                        "runs": [
                            {
                                "text": "ParseHub",
                                "navigationEndpoint": {
                                    "clickTrackingParams": "CIcDENwwGAAiEwjhusGS9eeRAxVgsCsGHUckAefKAQTO5BLD",
                                    "commandMetadata": {
                                        "webCommandMetadata": {
                                            "url": "/@ParsehubApp",
                                            "webPageType": "WEB_PAGE_TYPE_CHANNEL",
                                            "rootVe": 3611,
                                            "apiUrl": "/youtubei/v1/browse"
                                        }
                                    },
                                    "browseEndpoint": {
                                        "browseId": "UCqHoe4Ixju1bcOy0jHPO8Kg",
                                        "canonicalBaseUrl": "/@ParsehubApp"
                                    }
                                }
                            }
                        ]
                    }
                }
            ]
        }
    ]
  }
  ```
</CodeGroup>

***

<Columns cols={2}>
  <Card title="支持" href="https://direct.lc.chat/12092754" cta="让我们聊聊！">
    需要帮助或只是想打个招呼？我们的支持团队全天候为您服务。 \
    您也可以随时通过电子邮件 [support@decodo.com](mailto:support@decodo.com) 联系我们。
  </Card>

  <Card title="反馈" href="mailto:feedback@decodo.com" cta="分享反馈">
    找不到您要找的内容？请求一篇文章！ \
    有反馈意见？分享您对我们如何改进的想法。
  </Card>
</Columns>
