scraping-youtube-videos-by-keyword
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseScraping YouTube Videos by Keyword
按关键词抓取YouTube视频
Raw YouTube video dataset for any search query. Returns video-level metadata including engagement metrics and channel info.
针对任意搜索查询的原始YouTube视频数据集。返回包含互动指标和频道信息的视频级元数据。
Prerequisites
前提条件
- environment variable set
APIFY_TOKEN - Optional: Apify MCP server installed
- 已设置环境变量
APIFY_TOKEN - 可选:已安装Apify MCP服务器
Inputs
输入参数
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| array | Optional | | YouTube URLs — channels, playlists, Shorts, search results |
| array | Optional | | YouTube channel handles (e.g. |
| boolean | Optional | | Retrieve trending videos |
| array | Optional | | Search keywords |
| string | Optional | | Country code for results (e.g. |
| string | Optional | | Language code (e.g. |
| string | Optional | | Upload date filter: |
| string | Optional | | Duration filter: |
| string | Optional | | Feature filter: |
| string | Optional | | Sort order for search results |
| number | Optional | Unlimited | Maximum videos to return |
| string | Optional | — | JavaScript function to transform each output object |
| 参数 | 类型 | 是否必填 | 默认值 | 说明 |
|---|---|---|---|---|
| 数组 | 可选 | | YouTube URL — 频道、播放列表、Shorts、搜索结果 |
| 数组 | 可选 | | YouTube频道账号(例如 |
| 布尔值 | 可选 | | 获取热门视频 |
| 数组 | 可选 | | 搜索关键词 |
| 字符串 | 可选 | | 结果对应的国家代码(例如 |
| 字符串 | 可选 | | 语言代码(例如 |
| 字符串 | 可选 | | 上传日期筛选: |
| 字符串 | 可选 | | 时长筛选: |
| 字符串 | 可选 | | 功能筛选: |
| 字符串 | 可选 | | 搜索结果的排序方式 |
| 数字 | 可选 | 无限制 | 返回的最大视频数量 |
| 字符串 | 可选 | — | 用于转换每个输出对象的JavaScript函数 |
Workflow
工作流程
Progress:
- [ ] Step 1: Build search query
- [ ] Step 2: Run youtube-scraper
- [ ] Step 3: Poll for SUCCEEDED
- [ ] Step 4: Deliver video dataset进度:
- [ ] 步骤1:构建搜索查询
- [ ] 步骤2:运行youtube-scraper
- [ ] 步骤3:轮询直至状态为SUCCEEDED
- [ ] 步骤4:交付视频数据集Step 2: Run the Actor
步骤2:运行Actor
Recommended — run_actor.js (handles waiting, output, and file saving automatically):
bash
undefined推荐方式 — run_actor.js(自动处理等待、输出和文件保存):
bash
undefinedQuick answer (prints table to chat)
快速输出(在聊天中打印表格)
node scripts/run_actor.js
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
node scripts/run_actor.js
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
Save as CSV
保存为CSV
node scripts/run_actor.js
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
node scripts/run_actor.js
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
Save as JSON
保存为JSON
node scripts/run_actor.js
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
> `APIFY_TOKEN` must be set in environment or `.env` file.
**If Apify MCP is available:**Tool: apify:run-actor
Actor: "apidojo~youtube-scraper"
Input:
{
"searchKeywords": "<query>",
"maxResults": 50,
"sortBy": "relevance"
}
**REST API fallback:**
```bash
curl -X POST \
"https://api.apify.com/v2/acts/apidojo~youtube-scraper/runs?token=$APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"searchKeywords": "<query>", "maxResults": 50}'Save as . Poll until :
idRUN_IDstatus = SUCCEEDEDbash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID?token=$APIFY_TOKEN" | grep '"status"'Fetch results:
bash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID/dataset/items?token=$APIFY_TOKEN&format=json"node scripts/run_actor.js
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
--actor "apidojo~youtube-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
> 必须在环境变量或`.env`文件中设置`APIFY_TOKEN`。
**如果Apify MCP可用:**工具: apify:run-actor
Actor: "apidojo~youtube-scraper"
输入:
{
"searchKeywords": "<query>",
"maxResults": 50,
"sortBy": "relevance"
}
**REST API备选方案:**
```bash
curl -X POST \
"https://api.apify.com/v2/acts/apidojo~youtube-scraper/runs?token=$APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"searchKeywords": "<query>", "maxResults": 50}'将返回的保存为。轮询直至:
idRUN_IDstatus = SUCCEEDEDbash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID?token=$APIFY_TOKEN" | grep '"status"'获取结果:
bash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID/dataset/items?token=$APIFY_TOKEN&format=json"Step 3: Handle Edge Cases
步骤3:处理边缘情况
- < 20 results: Query may be too narrow; broaden search term.
- Age-restricted content in results: These may have limited metadata — flag rows with missing .
viewCount - Duplicate video IDs: Deduplicate by .
videoId
- 结果少于20条:查询范围可能过窄,请扩大搜索词范围。
- 结果中包含年龄限制内容:这类视频的元数据可能有限 — 标记缺失的行。
viewCount - 重复视频ID:按去重。
videoId
Output Format
输出格式
undefinedundefinedYouTube Video Dataset: "<query>"
YouTube视频数据集: "<query>"
Videos collected: N | Sort: <sortBy>
| Video ID | Title | Channel | Views | Likes | Comments | Duration | Published |
|---|---|---|---|---|---|---|---|
| ... | ... | ... | ... | ... | ... | ... | ... |
Available fields: videoId, title, channelName, channelId, viewCount, likeCount,
commentCount, duration, publishedAt, videoUrl, thumbnailUrl, description
undefined收集到的视频数量: N | 排序方式: <sortBy>
| 视频ID | 标题 | 频道 | 观看量 | 点赞量 | 评论数 | 时长 | 发布日期 |
|---|---|---|---|---|---|---|---|
| ... | ... | ... | ... | ... | ... | ... | ... |
可用字段: videoId, title, channelName, channelId, viewCount, likeCount,
commentCount, duration, publishedAt, videoUrl, thumbnailUrl, description
undefinedTroubleshooting
故障排除
Fewer results than requested: YouTube search may have limited results for niche queries.
Missing like counts: YouTube hides dislikes but likes are still available; some videos hide all counts.
结果数量少于请求值:针对小众查询,YouTube搜索的结果可能有限。
点赞量缺失:YouTube隐藏了点踩数,但点赞数仍然可用;部分视频会隐藏所有互动数据。