All articles

How to scrape TikTok with Python

Published Date Apr 22, 2025
Read 6 min
How to scrape TikTok with Python

TL;DR

  • Build a Python scraper to extract TikTok profile data (username, avatar, followers/following, bio, website).

  • Use Scrapingdog to fetch dynamic HTML (free 1,000-credit trial), then parse with BeautifulSoup.

  • Store records with pandas to tiktok.csv (sample output shown).

  • Scrapingdog handles proxies, CAPTCHAs, and headers so TikTok scraping stays reliable.

Scraping TikTok data can unlock powerful insights, from tracking viral trends to analyzing influencer reach and engagement. Whether you’re a marketer trying to identify the next big influencer, a brand looking to track trends, or a researcher analyzing user engagement, extracting data from TikTok can provide powerful insights.

In this blog, I’ll show you how to scrape real-time insights from TikTok using Python.

What will you learn?

In this guide, we will use various tools to extract data from TikTok. But before we begin, let me just give you an overview of what you will learn in this article.

  • Basic Python scraper setup with proper library installation.

  • Scraping TikTok with a Web Scraping API.

  • We’ll be scraping key profile attributes such as follower count, following count, profile picture URL, and bio information.

  • Store data in a CSV file.

If you’re new to web scraping, I highly recommend reading Web Scraping with Python to gain valuable insights. This guide will help you build a solid foundation, making it easy to scrape data from virtually any website.

Requirements

I hope you have already installed Python on your computer; if not, then you can install it from here. Now, create a folder in which we will keep the project files.

1mkdir tiktok

Install three libraries inside this folder.

  • requests for making an HTTP connection with the target website.

  • BeautifulSoup for parsing the raw data.

  • Pandas for storing data in a CSV file.

    `pip install requests pip install beautifulsoup4 pip install pandas`

Now, sign up for the free trial pack. The trial pack includes 1000 credits, which are enough to build a small scraper.

scrapingdog homepage

Finally, create a Python file in which we will code our TikTok scraper. I am naming this file as social.py.

Scraping TikTok with Python

Let’s first decide what exactly we want to scrape from TikTok

1 v TLWmumEaJP2Skw8RIIXw
  1. Profile picture

  2. Username

  3. Number of followers

  4. Number of following Accounts

  5. Website link.

  6. Bio.

Analyzing the HTML structure of the page

1 2JkrEOtJiAMkinIVPZVorg

Profile picture is located inside the img tag with class css-1zpj2q-ImgAvatar_._

1 LaFdY0uI 2UX1Lglxhp8Pg

The username is located inside the h1 tag.

1 Bj03eA7yO3pwgZyJ2879Ew

The number of followers is located inside the strong tag with the attribute title and value Followers.

1 XxnLdYGPo9Z6w8y3NC3FjQ

Similarly, the following count is located inside the strong tag with attribute title and value Following.

1 Jb51XMQdsARRfHsIkGbh g

Bio is located inside an h2 tag with attribute data-e2e and value user-bio.

1 o n RkRoZF2fW74 TJuM9w

The website link is located inside an a tag with an attribute data-e2e and value user-link.

Profile

img tag with class css-1zpj2q-ImgAvatar.

Username

h1 tag

Followers

strong tag with the attribute title and value Followers

Following

strong tag with attribute title and value Following

Bio

h2 tag with attribute data‑e2e and value user‑bio

Website

a tag with an attribute data‑e2e and value user‑link

We have the location of each element. Now, we can code and extract this data.

Download data from TikTok

Before we start coding, I recommend reading the documentation of Scrapingdog.

1import requests
2from bs4 import BeautifulSoup
3
4
5params={
6 'api_key': 'your-api-key',
7 'url': 'https://www.tiktok.com/@kimkardashian?lang=en',
8 'dynamic': 'true',
9 'wait': '3000',
10 }
11
12response = requests.get("https://api.scrapingdog.com/scrape", params=params)
13
14
15print("status code is ",response.status_code)
16print(response.text)

The code is straightforward, but let me explain you step by step.

  • First, we have imported the libraries that we installed earlier.

  • Then, we created a params object containing the necessary parameters required to make a request to the Scrapingdog Web Scraping API.

  • Using requests, we made a GET request to the API.

  • Finally, we are printing the status of the request and the downloaded data.

Once we run this code, you will get this on your console.

1 k6rpfbVA6O2Va3qBz3AafA

As you can see, we got a 200 status code. Now, we can proceed ahead and parse the data using BS4.

Parsing data from TikTok using BeautifulSoup

1soup = BeautifulSoup(response.text, 'html.parser')
2
3try:
4 obj["username"]=soup.find("h1").text
5except:
6 obj["username"]=None
7
8try:
9 obj["profile"]=soup.find("img",{"class":"css-1zpj2q-ImgAvatar"}).get('src')
10except:
11 obj["profile"]=None
12
13
14try:
15 obj["following"]=soup.find("strong",{"title":'Following'}).text
16except:
17 obj["following"]=None
18
19try:
20 obj["followers"]=soup.find("strong",{"title":'Followers'}).text
21except:
22 obj["followers"]=None
23
24try:
25 obj["Bio"]=soup.find("h2",{"data-e2e":'user-bio'}).text
26except:
27 obj["Bio"]=None
28
29try:
30 obj["website"]=soup.find("a",{"data-e2e":"user-link"}).get('href')
31except:
32 obj["website"]=None
33
34l.append(obj)
35
36print(l)

Here using the find() function of BeautifulSoup I have extracted the text value of each element. Once you run the code you should see this data on your console.

1[{'username': 'kimkardashian',
2'profile': 'https://p19-pu-sign-useast8.tiktokcdn-us.com/tos-useast5-avt-0068-tx/7310049872432857130~tplv-tiktokx-cropcenter:1080:1080.jpeg?dr=9640&refresh_token=bad80b71&x-expires=1745485200&x-signature=C2YQZ3vduWrLxGgZ%2BaG%2FkwvZ3O4%3D&t=4d5b0474&ps=13740610&shp=a5d48078&shcp=81f88b70&idc=useast5',
3'following': '15',
4'followers': '9.9M',
5'Bio': 'No bio yet.',
6'website': 'https://www.tiktok.com/link/v2?aid=1988&lang=en&scene=bio_url&target=skims.social%2Fkim_sale_tiktok'
7}]

As you can see, we are successfully able to scrape & parse all the data from TikTok with the help of Scrapingdog and Python.

Saving data to a CSV file

For this part, we will need the help of the pandas library.

1df = pd.DataFrame(l)
2df.to_csv('tiktok.csv', index=False, encoding='utf-8')

After running the code, you will get a tiktok.csv file inside your folder.

1 kOsRKk jrITppCfpnqBz6w

Complete Code

We can scrape video stats too from TikTok for any particular video, I will leave this exercise to you. But for the current scenario, the code will look like this.

1import requests
2from bs4 import BeautifulSoup
3import pandas as pd
4
5l=[]
6obj={}
7
8params={
9 'api_key': 'your-api-key',
10 'url': 'https://www.tiktok.com/@kimkardashian?lang=en',
11 'dynamic': 'true',
12 'wait': '10000',
13 }
14
15response = requests.get("https://api.scrapingdog.com/scrape", params=params)
16
17
18print("status code is ",response.status_code)
19
20soup = BeautifulSoup(response.text, 'html.parser')
21
22try:
23 obj["username"]=soup.find("h1").text
24except:
25 obj["username"]=None
26
27try:
28 obj["profile"]=soup.find("img",{"class":"css-1zpj2q-ImgAvatar"}).get('src')
29except:
30 obj["profile"]=None
31
32
33try:
34 obj["following"]=soup.find("strong",{"title":'Following'}).text
35except:
36 obj["following"]=None
37
38try:
39 obj["followers"]=soup.find("strong",{"title":'Followers'}).text
40except:
41 obj["followers"]=None
42
43try:
44 obj["Bio"]=soup.find("h2",{"data-e2e":'user-bio'}).text
45except:
46 obj["Bio"]=None
47
48try:
49 obj["website"]=soup.find("a",{"data-e2e":"user-link"}).get('href')
50except:
51 obj["website"]=None
52
53l.append(obj)
54print(l)
55df = pd.DataFrame(l)
56df.to_csv('tiktok.csv', index=False, encoding='utf-8')

Here are Some Key Takeaways:

  • Shows how to extract TikTok video and profile data using Python and a scraping API.

  • Demonstrates retrieving structured information like video URLs, captions, and metrics.

  • The scraping setup handles proxies and anti-bot protection automatically.

  • Includes example Python code to make API requests and parse the responses.

  • Useful for trend analysis, content research, and social media data workflows.

Conclusion

Scraping TikTok data can be a valuable asset for market research, trend analysis, or even content strategy. However, due to TikTok’s strict anti-bot measures, scraping it directly can be quite challenging. That’s where Scrapingdog steps in, it simplifies the process by handling all the heavy lifting, like proxy rotation, CAPTCHA solving, and headers management.

It also utilizes static residential proxies to ensure more consistent access and reduce the chances of detection or blocking.

Using Python, you’ve seen how easy it is to integrate Scrapingdog’s Web Scraping API to extract TikTok data efficiently without hitting constant roadblocks. Whether you’re tracking influencers, analyzing engagement, or pulling video metadata, this approach ensures reliability and scalability.

Additional Resources

Try Scrapingdog for Free!

Get 200 free credits to spin the API. No credit card required!