scraping-youtube-trending-videos

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Scraping Youtube Trending Videos

爬取YouTube热门视频

Raw data collection. No assumed use case — returns the full dataset for downstream analysis.

原始数据采集。不预设使用场景——返回完整数据集以供下游分析。

Inputs

输入参数

ParameterTypeRequiredDefaultNotes
type
stringOptional
n
Trending category:
n
(now),
music
,
movies
,
gaming
gl
stringOptional
us
Country code (e.g.
US
,
GB
)
hl
stringOptional
en
Language code (e.g.
en
)
maxItems
numberOptionalUnlimitedMaximum videos to return
customMapFunction
stringOptionalJavaScript function to transform each output object
参数类型是否必填默认值说明
type
string可选
n
热门类别:
n
(当前)、
music
(音乐)、
movies
(电影)、
gaming
(游戏)
gl
string可选
us
国家代码(例如
US
GB
hl
string可选
en
语言代码(例如
en
maxItems
number可选无限制返回的最大视频数量
customMapFunction
string可选用于转换每个输出对象的JavaScript函数

How to Run

运行方式

Using run_actor.js (recommended)

使用run_actor.js(推荐)

bash
undefined
bash
undefined

Quick answer (table)

快速查看结果(表格形式)

node scripts/run_actor.js --actor "apidojo~youtube-trending-scraper" --input '{"type": "n", "gl": "us", "hl": "en", "maxItems": 50}'
node scripts/run_actor.js --actor "apidojo~youtube-trending-scraper" --input '{"type": "n", "gl": "us", "hl": "en", "maxItems": 50}'

Save as CSV

保存为CSV格式

node scripts/run_actor.js --actor "apidojo~youtube-trending-scraper" --input '{"type": "n", "gl": "us", "hl": "en", "maxItems": 50}' --output results.csv --format csv
node scripts/run_actor.js --actor "apidojo~youtube-trending-scraper" --input '{"type": "n", "gl": "us", "hl": "en", "maxItems": 50}' --output results.csv --format csv

Save as JSON

保存为JSON格式

node scripts/run_actor.js --actor "apidojo~youtube-trending-scraper" --input '{"type": "n", "gl": "us", "hl": "en", "maxItems": 50}' --output results.json --format json
undefined
node scripts/run_actor.js --actor "apidojo~youtube-trending-scraper" --input '{"type": "n", "gl": "us", "hl": "en", "maxItems": 50}' --output results.json --format json
undefined

REST API fallback

REST API备选方案

bash
curl -X POST "https://api.apify.com/v2/acts/apidojo~youtube-trending-scraper/runs" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "n", "gl": "us", "hl": "en", "maxItems": 50}'
If Apify MCP is available: Use the Apify MCP
call_actor
tool with actor
apidojo~youtube-trending-scraper
and the input above.

bash
curl -X POST "https://api.apify.com/v2/acts/apidojo~youtube-trending-scraper/runs" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "n", "gl": "us", "hl": "en", "maxItems": 50}'
如果Apify MCP可用: 使用Apify MCP的
call_actor
工具,指定actor为
apidojo~youtube-trending-scraper
并传入上述输入参数。

Output Fields

输出字段

FieldTypeDescription
type
stringAlways
video
id
stringVideo ID
title
stringVideo title
url
stringVideo URL
description
stringVideo description
duration
numberDuration in seconds
views
numberView count
likes
numberLike count
status
stringAvailability status
channel.id
stringChannel ID
channel.name
stringChannel name
channel.url
stringChannel URL
keywords
arrayVideo tags/keywords
isLive
booleanLive stream flag
thumbnails
arrayThumbnail objects
字段类型描述
type
string固定为
video
id
string视频ID
title
string视频标题
url
string视频URL
description
string视频描述
duration
number视频时长(秒)
views
number观看量
likes
number点赞数
status
string可用状态
channel.id
string频道ID
channel.name
string频道名称
channel.url
string频道URL
keywords
array视频标签/关键词
isLive
boolean直播标识
thumbnails
array缩略图对象

Edge Cases

边缘情况

  • No results for category: Some countries may not have all category pages. Fall back to type=
    n
    .
  • Empty results: YouTube may show different trending per session — retry.
  • Region mismatch: gl and hl must be valid ISO codes.
  • Data freshness: Trending changes frequently — data reflects a point-in-time snapshot.
  • 类别无结果:部分国家可能没有全部分类页面,回退到
    type=n
  • 结果为空:YouTube可能会根据会话显示不同的热门内容——请重试。
  • 区域不匹配
    gl
    hl
    必须是有效的ISO代码。
  • 数据时效性:热门内容变化频繁——数据反映的是某一时刻的快照。