Script to parse comments from TikTok
Requires authentication via Google Account.
If you have problems, head to Problems section and to Issues.
- Prerequisites. This script works on Linux and Mac systems. Good work is not guaranteed for Windows. Create python virtual environment and install dependencies.
python3 -m venv/
source venv/bin/activate
python3 -m pip install -r requirements.txt
- Open terminal and set environment variables EMAIL, PASSWORD, COMMENTS_LIMIT with gmail account email and password.
COMMENTS_LIMIT is used to limit comment parsing for posts with lots of comments. For example, if COMMENTS_LIMIT = 100, than script will parse first 100 comments and then stop. If COMMENTS_LIMIT is too big, script will work for too long.
export EMAIL=<[email protected]> && \
export PASSWORD=<password_for_google_account> && \
export COMMENTS_LIMIT=<comment_limit>
- Copy-paste link to video you want to parse into the
input.txt
.
echo "https://www.tiktok.com/?lang=en&is_copy_url=1&is_from_webapp=v3&item_id=6906436719541767425#/@youneszarou/video/6906436719541767425" >input.txt
- Run python script
tiktok.py
.
python3 tiktok.py <input.txt
CSV file with columns: id
, nickname
, link_to_profile
, text
, like_count
. No headers!
TODO: comment's answers.
Grows in non-linear way:
Comment amt | Time |
---|---|
100 | ~ 0 |
2000 | ~1min |
5000 | ~10min |
Speed is limited not only to language, technologies and parsing technique, but also to TikTok limitations. TikTok is against parsing and it will cause as many problems to parse as possible. For example:
- Comments are loaded in batches of 20 comments each.
- Next batch of comments can be loaded only after previous one was done. No way to make process parallel.
- After parsing of about 1000 comments TikTok starts to make delays for about 1sec per batch. Further it will become 5sec and so on...
So we can't make this process parallel, but we can try to make this process use several accounts. Comments for different users are mixed.
Python, selenium
- Login in TikTok via Google Auth
- Open the post.
- Open comment section.
- Load comments, scrolling down.
- Write all comments to csv.
Do not touch Chromium while it's working!
This browser or app may not be secure. Go to Google Account Settings, go to Security
and enable Less secure app access
. Also disable two-factor auth. Then try again. Even with this done there still can be problems.
Comment section doesn't open It is a problem, just try again. Double check the link is valid.
White screen and no video. It is a problem, and it seems to be TikTok ban.
OMG IT IS NOT WORKING AT ALL! Navigate to the Issues of this repo, open an issue and describe in full details what happened. We will try to help.