scraping-tiktok-comments

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Scraping TikTok Comments

抓取TikTok评论

Exports all comments from any TikTok video URL. Returns the raw comment dataset for sentiment analysis, community research, or product feedback extraction.
导出任意TikTok视频URL的所有评论。返回原始评论数据集,用于情感分析、社区研究或产品反馈提取。

Prerequisites

前提条件

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

Inputs

输入参数

ParameterTypeRequiredDefaultNotes
startUrls
array
[]
TikTok video URLs to scrape comments from
includeReplies
booleanOptional
false
Include reply comments (nested)
maxItems
numberOptionalUnlimitedMaximum comments to return
customMapFunction
stringOptionalJavaScript function to transform each output object
参数类型是否必填默认值说明
startUrls
数组
[]
要抓取评论的TikTok视频URL
includeReplies
布尔值可选
false
是否包含回复评论(嵌套评论)
maxItems
数字可选无限制返回的最大评论数
customMapFunction
字符串可选用于转换每个输出对象的JavaScript函数

Workflow

工作流程

Progress:
- [ ] Step 1: Validate video URLs
- [ ] Step 2: Run tiktok-comments-scraper
- [ ] Step 3: Poll for SUCCEEDED
- [ ] Step 4: Deliver comment dataset
Progress:
- [ ] Step 1: Validate video URLs
- [ ] Step 2: Run tiktok-comments-scraper
- [ ] Step 3: Poll for SUCCEEDED
- [ ] Step 4: Deliver comment dataset

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)

Quick answer (prints table to chat)

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

Save as CSV

Save as CSV

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

Save as JSON

Save as JSON

node scripts/run_actor.js
--actor "apidojo~tiktok-comments-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~tiktok-comments-scraper" Input: { "videoUrls": ["https://www.tiktok.com/@user/video/123456"], "maxItems": 200, "includeReplies": false }

**REST API fallback:**
```bash
curl -X POST \
  "https://api.apify.com/v2/acts/apidojo~tiktok-comments-scraper/runs?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"videoUrls": ["<url>"], "maxItems": 200}'
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~tiktok-comments-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
> `APIFY_TOKEN`必须在环境变量或`.env`文件中设置。

**如果Apify MCP可用:**
Tool: apify:run-actor Actor: "apidojo~tiktok-comments-scraper" Input: { "videoUrls": ["https://www.tiktok.com/@user/video/123456"], "maxItems": 200, "includeReplies": false }

**REST API备选方案:**
```bash
curl -X POST \
  "https://api.apify.com/v2/acts/apidojo~tiktok-comments-scraper/runs?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"videoUrls": ["<url>"], "maxItems": 200}'
保存
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:处理边缘情况

  • 0 comments: Video may have comments disabled or be private. Report to user.
  • Video deleted or unavailable: Actor returns error — remove URL from batch and notify.
  • Comment count less than expected: TikTok filters spam comments server-side; this is expected.
  • 0条评论:视频可能已禁用评论或为私有视频。需告知用户。
  • 视频已删除或不可用:Actor返回错误 — 从批量任务中移除该URL并通知用户。
  • 评论数少于预期:TikTok会在服务器端过滤垃圾评论;这属于正常情况。

Output Format

输出格式

undefined
undefined

TikTok Comment Dataset

TikTok Comment Dataset

Video: <url> | Comments collected: N | Includes replies: YES/NO
Comment IDAuthorTextLikesRepliesTimestamp
..................
Available fields: id, text, authorUsername, diggCount, replyCount, createTime, isReply, parentCommentId
undefined
Video: <url> | Comments collected: N | Includes replies: YES/NO
Comment IDAuthorTextLikesRepliesTimestamp
..................
Available fields: id, text, authorUsername, diggCount, replyCount, createTime, isReply, parentCommentId
undefined

Troubleshooting

故障排除

Comments disabled: Creator has disabled comments — no workaround. Truncated comments: Some comments may be cut off by TikTok's API; full text available via video page.
评论已禁用:创作者已禁用评论 — 无解决办法。 评论被截断:部分评论可能被TikTok的API截断;完整文本可通过视频页面查看。