How to Collect Data from TikTok
Oleg Kulyk
Co-Founder @ ScrapingAntThere is a lot of news related to TikTok being sold to US companies and the issue of scraping TikTok data becomes more real due to the possible closing of the service.
#
How to scrape TikTok videos posted or liked by a user, collect a large user list from seed accounts, and collect trending videos - all with a simple API.In short, TikTok now has a sizeable real-world influence, especially considering that a typical user spends almost an hour per day watching videos on the platform. With this in mind, it is important to understand what TikTok shows to millions of eyeballs every day. To do that, we will need some data.
So, in this guide, we'd like to introduce the method of collecting useful data from this media service using the Python library TikTokApi. The following topics will be covered:
- ๐ค Collecting videos posted by a user
- โค๏ธ Collecting videos liked by a user
- ๐ท๏ธ Collecting videos by hashtag
- ๐ Collecting trending videos
- ๐ง๐ฝโ๐คโ๐ง๐ฝ Collecting a list of users (by a seed account)
#
0. ๐ค Prepare the dependenciesRather than rewrite all the simple steps, please, check out the official TikTokApi Github repository to be up to date: https://github.com/davidteather/TikTok-Api#getting-started
Also, to start scraping in scale, we'd like to suggest using proxies to avoid a TikTok ban. Check our free proxies list: https://scrapingant.com/free-proxies/
#
1. ๐ค Collecting videos posted by a userTo scrape videos from the Kourtney Kardashian - @kourtneykardashian TikTok account, here is what we need to do in Python:
The user_videos
object is now a list of 100 video dictionaries, and the print(user_videos)
output will look like the following:
#
2. โค๏ธ Collecting videos liked by a userLet's continue working with Kourtney Kardashian TikTok account and check what videos have been liked by this account:
#
3. ๐ท๏ธ Collecting videos by hashtagLet's check out what videos we can scape by the #kardashian hashtag:
#
4. ๐ Collecting trending videosMaybe you just need to collect trending videos for content analysis. The API makes that pretty simple:
#
5. ๐ง๐ฝโ๐คโ๐ง๐ฝ Collecting a list of users from a seed accountThis is probably the most interesting part of the analysis and machine learning experiments. So, for example, we'd like to get all suggested users for Kourtney Kardashian for further retrieving of TikToks:
#
SummaryTikTok provides a large amount of useful data that can be converted into a machine learning dataset or used for manual analysis. Also, media research allows an understanding of trends dynamic for creating the most popular account.