There 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.
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)
Rather 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/
To scrape videos from the Kourtney Kardashian - @kourtneykardashian TikTok account, here is what we need to do in Python:
user_videos object is now a list of 100 video dictionaries, and the
print(user_videos) output will look like the following:
Let's continue working with Kourtney Kardashian TikTok account and check what videos have been liked by this account:
Let's check out what videos we can scape by the #kardashian hashtag:
Maybe you just need to collect trending videos for content analysis. The API makes that pretty simple:
This 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:
TikTok 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.