DEV Community

Cover image for Get TikTok video with less than 10 Lines of Python code

Posted on


Get TikTok video with less than 10 Lines of Python code

Actually TikTok offers some endpoints for developers, but that doesn't have many functionality and flexibility.

In this post, we will use the following.

GitHub logo davidteather / TikTok-Api

The Unofficial TikTok API Wrapper In Python

Unofficial TikTok API in Python

This is an unofficial api wrapper for in python. With this api you are able to call most trending and fetch specific user information as well as much more.

DOI LinkedIn Sponsor Me GitHub release (latest by date) Build Status GitHub Downloads Support Server


These sponsors have paid to be placed here and beyond that I do not have any affiliation with them, the TikTokAPI package will always be free and open-source. If you wish to be a sponsor of this project check out my GitHub sponsors page.

This python library allows us to use TikTok data easily and documents are organized very well.

The official doc

Step1. install the library via pip

$ pip install TikTokApi
$ python -m playwright install
Enter fullscreen mode Exit fullscreen mode

Step2. get custom_verifyFp

Go to TikTok and open Dev Tool > Application > Storage > Cookies. Then copy s_v_web_id value and paste it to verifyFp in the following sample code.

You can see what you need to do to get s_v_web_id in the Youtube video.

In this sample code, I used by_hashtag method that gets the fixed number of videos that have Messi as a #tag.
In the sample, I set 10 as count.

By the way the Youtube video uses by_trending

from TikTokApi import TikTokApi
api = TikTokApi.get_instance(custom_verifyFp=verifyFp, use_test_endpoints=True)
results = 10
hashtag = 'Messi'
search_results = api.by_hashtag(count=results, hashtag=hashtag)
for tiktok in search_results:
Enter fullscreen mode Exit fullscreen mode

Step3. run the sample code

You can get the video links.

$ python
Enter fullscreen mode Exit fullscreen mode

If you want to know the general return, you can see it ↓

Top comments (2)

ademvincen profile image
AdemVincen • Edited

Great post on how to get TikTok videos with just a few lines of Python code. As a fellow Python enthusiast, I really appreciate the simplicity of the code you shared. This is a great place to start for those new to programming or just beginning to explore the world of Python. And for those already familiar with the language, this code provides a quick and easy solution for downloading TikTok videos. Have you tried using the Download TikTok Video tool? It's a great way to quickly download and save TikTok videos to your device without having to go through the hassle of writing any code. If interested, give it a try and let us know what you think!

gellrows profile image

As a programmer, I really enjoyed these videos.