scraping-youtube-channel-data

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Scraping YouTube Channel Data

抓取YouTube频道数据

Exports channel-level statistics and optional video catalog for any YouTube channel URL or handle.
导出任意YouTube频道URL或频道标识对应的频道级统计数据及可选视频目录。

Prerequisites

前提条件

  • APIFY_TOKEN
    environment variable set
  • Optional: Apify MCP server installed
  • 已设置
    APIFY_TOKEN
    环境变量
  • 可选:已安装Apify MCP服务器

Inputs

输入参数

ParameterTypeRequiredDefaultNotes
startUrls
arrayOptional
[]
YouTube URLs — channels, playlists, Shorts, search results
youtubeHandles
arrayOptional
[]
YouTube channel handles (e.g.
@kurzgesagt
)
getTrending
booleanOptional
false
Retrieve trending videos
keywords
arrayOptional
[]
Search keywords
gl
stringOptional
us
Country code for results (e.g.
US
,
GB
)
hl
stringOptional
en
Language code (e.g.
en
,
de
)
uploadDate
stringOptional
all
Upload date filter:
any
,
hour
,
today
,
week
,
month
,
year
duration
stringOptional
all
Duration filter:
any
,
short
,
long
features
stringOptional
all
Feature filter:
4k
,
hd
,
live
,
cc
,
3d
,
hdr
, etc.
sort
stringOptional
r
Sort order for search results
maxItems
numberOptionalUnlimitedMaximum videos to return
customMapFunction
stringOptionalJavaScript function to transform each output object
参数类型是否必填默认值说明
startUrls
数组可选
[]
YouTube链接 — 频道、播放列表、Shorts、搜索结果
youtubeHandles
数组可选
[]
YouTube频道标识(例如
@kurzgesagt
getTrending
布尔值可选
false
获取热门视频
keywords
数组可选
[]
搜索关键词
gl
字符串可选
us
结果对应的国家代码(例如
US
GB
hl
字符串可选
en
语言代码(例如
en
de
uploadDate
字符串可选
all
上传时间筛选:
any
(任意时间)、
hour
(最近1小时)、
today
(今天)、
week
(本周)、
month
(本月)、
year
(本年)
duration
字符串可选
all
时长筛选:
any
(任意时长)、
short
(短视频)、
long
(长视频)
features
字符串可选
all
功能筛选:
4k
hd
live
(直播)、
cc
(字幕)、
3d
hdr
sort
字符串可选
r
搜索结果排序方式
maxItems
数字可选无限制返回的最大视频数量
customMapFunction
字符串可选用于转换每个输出对象的JavaScript函数

Workflow

工作流程

Progress:
- [ ] Step 1: Normalize channel URLs
- [ ] Step 2: Run youtube-scraper
- [ ] Step 3: Poll for SUCCEEDED
- [ ] Step 4: Deliver channel dataset
进度:
- [ ] 步骤1:标准化频道URL
- [ ] 步骤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
undefined

Quick answer (prints table to chat)

快速查看(在聊天窗口打印表格)

node scripts/run_actor.js
--actor "apidojo~youtube-channel-scraper"
--input '{"param": "value"}'
node scripts/run_actor.js
--actor "apidojo~youtube-channel-scraper"
--input '{"param": "value"}'

Save as CSV

保存为CSV

node scripts/run_actor.js
--actor "apidojo~youtube-channel-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
node scripts/run_actor.js
--actor "apidojo~youtube-channel-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv

Save as JSON

保存为JSON

node scripts/run_actor.js
--actor "apidojo~youtube-channel-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-channel-scraper" Input: { "channelUrls": ["https://www.youtube.com/@channelhandle"], "maxVideos": 30 }

**REST API fallback:**
```bash
curl -X POST \
  "https://api.apify.com/v2/acts/apidojo~youtube-channel-scraper/runs?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channelUrls": ["https://www.youtube.com/@channelhandle"], "maxVideos": 30}'
Save
id
as
RUN_ID
. Poll until
status = SUCCEEDED
:
bash
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-channel-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
> 必须在环境变量或`.env`文件中设置`APIFY_TOKEN`。

**若Apify MCP可用:**
工具: apify:run-actor Actor: "apidojo~youtube-channel-scraper" 输入: { "channelUrls": ["https://www.youtube.com/@channelhandle"], "maxVideos": 30 }

**REST API备选方案:**
```bash
curl -X POST \
  "https://api.apify.com/v2/acts/apidojo~youtube-channel-scraper/runs?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channelUrls": ["https://www.youtube.com/@channelhandle"], "maxVideos": 30}'
保存
id
RUN_ID
,轮询直至
status = SUCCEEDED
bash
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:处理边缘情况

  • Channel URL not found: Handle may have changed — verify on YouTube.
  • Hidden subscriber count: Some channels hide subscriber counts; field returns null — flag these.
  • Age-restricted channel: May return limited metadata.
  • 频道URL未找到:频道标识可能已更改,请在YouTube上验证。
  • 隐藏订阅数:部分频道会隐藏订阅数,该字段将返回null,请标记此类频道。
  • 年龄限制频道:可能仅返回有限的元数据。

Output Format

输出格式

undefined
undefined

YouTube Channel Dataset

YouTube频道数据集

Channels requested: N | Returned: N
ChannelSubscribersTotal ViewsVideosJoinedCountryRecent Avg Views
.....................
Available fields: channelName, channelId, subscriberCount, viewCount, videoCount, country, joinedDate, description, channelUrl, recentVideos[]
undefined
请求的频道数:N | 返回的频道数:N
频道订阅数总观看量视频数入驻时间国家近期平均观看量
.....................
可用字段:channelName、channelId、subscriberCount、viewCount、videoCount, country、joinedDate、description、channelUrl、recentVideos[]
undefined

Troubleshooting

故障排查

Hidden subscriber count: YouTube allows channels to hide this — return
null
and note in output. Large video catalogs: Set
maxVideos: 100
max per run to avoid timeouts.
隐藏订阅数:YouTube允许频道隐藏该数据 — 返回
null
并在输出中注明。 大型视频目录:每次运行设置
maxVideos: 100
上限以避免超时。