DEV Community

Clear Fetch
Clear Fetch

Posted on

Export TikTok comments to CSV without the official API

TikTok has no "download comments" button, and its Research API is limited to approved academic researchers. Yet
comments are what marketers, agencies and analysts want most: picking a giveaway winner, reading the reaction to a
campaign, collecting text for sentiment analysis. Here is the shortest route I know from a video link to a
spreadsheet.

One command

curl -X POST "https://api.apify.com/v2/acts/clearfetch~tiktok-comments-scraper/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN&format=csv" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["https://www.tiktok.com/@tiktok/video/7106594312292453675"], "maxCommentsPerVideo": 500}' \
  -o comments.csv
Enter fullscreen mode Exit fullscreen mode

format=xlsx gives you an Excel file instead, and &fields=createdAt,likes,text keeps only the columns you name.
The first rows of a real run with those three fields:

"createdAt","likes","text"
"2022-08-05T18:01:11.000Z","3","Tiktok and Minecraft??"
"2022-06-07T21:03:06.000Z","156","15?"
"2022-06-22T22:36:33.000Z","190","j thought it was 16 because of the emoji😳"
Enter fullscreen mode Exit fullscreen mode

The token comes with a free Apify account. From Python it is the same call through the client:

from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("clearfetch/tiktok-comments-scraper").call(run_input={
    "urls": ["https://www.tiktok.com/@tiktok/video/7106594312292453675"],
    "maxCommentsPerVideo": 500,
    "includeReplies": True,
})
for c in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(c["createdAt"], c["likes"], c["text"])
Enter fullscreen mode Exit fullscreen mode

What each row holds

The comment text and time, its likes and reply count, whether it is a reply and to which comment, whether the
creator pinned or liked it, its language, the mentions and hashtags in it, a purchase-intent flag TikTok sets on some
comments, and the author's username, display name and profile link. Several video links go in one run, each row
tagged with its video.

Watching a video for new comments

Turn on onlyNew and schedule the run daily. The first run returns everything; every later run writes, and charges
for, only comments posted after the newest one already delivered for that video. TikTok orders comments by
popularity rather than date, so a new comment can sit anywhere in the list: let monitoring runs read all comments
("maxCommentsPerVideo": 0).

Things worth knowing

  • You will get fewer comments than the number under the video. That count includes replies and comments TikTok hides from everyone: filtered, deleted or restricted.
  • Repeats are dropped. TikTok's ranking shifts while you page through, so the same comment can come back on a later page; those are removed before they reach your file, and not charged.
  • Speed. About 100 comments a second on Apify's default settings: 20,000 comments in roughly four minutes.
  • Price. $0.40 per 1,000 comments, 10-30% less on paid Apify plans. No login, no cookies, no proxy needed.
  • Personal data. Comments are public, but usernames are personal data under laws such as the GDPR, so have a
    lawful reason to process them and store them appropriately.

  • Run it: apify.com/clearfetch/tiktok-comments-scraper

  • Examples (CSV export, scheduled monitoring): github.com/clearfetch/tiktok-comments-scraper

  • Ready-made pages:
    pick a TikTok giveaway winner from the comments,
    collect TikTok comments for sentiment analysis

Top comments (0)