This repo contains working scraping examples for TikTok using Playwright and direct TikTok internal API calls.
The scripts demonstrate how to capture TikTok API responses from the network layer, clean the data, and export structured JSON.
- Requirements
- Project Structure
- TikTok Profile Scraper
- TikTok Video Scraper
- TikTok Video Downloader
- TikTok Comments Scraper
- TikTok Search Scraper
- Disclaimer
- More Resources
- Python 3.8+
- pip
- Node.js 18+
- npm or yarn
- Playwright installed with browser dependencies:
pip install playwright
playwright installnpm install playwright
npx playwright installThe project is organized into two main folders: one for Python scripts and one for Node.js. Both have identical folder structures and contain the same functionality, but in different languages.
tiktok-scraper/
│
├── NodeJS/
│ ├── tiktok_comments_scraper.js # Scrape TikTok comments
│ ├── tiktok_profile_scraper.js # Scrape profile details and videos
│ ├── tiktok_search_scraper.js # Capture TikTok search results
│ ├── tiktok_video_downloader.js # Download TikTok videos
│ └── tiktok_video_scraper.js # General video scraping utilities
│
├── Python/
│ ├── tiktok_comments_scraper.py # Python version of comments scraper
│ ├── tiktok_profile_scraper.py # Python version of profile scraper
│ ├── tiktok_search_scraper.py # Python version of search scraper
│ ├── tiktok_video_downloader.py # Python version of video downloader
│ └── tiktok_video_scraper.py # Python version of video scraping utilities
│
├── banner.png # Optional repo banner image
└── README.md # Main documentation
This section covers the scripts that fetch TikTok profile data, including user details and uploaded videos.
The scripts use the HasData API to render the profile page and extract the secUid, which is then used to paginate through the user's video list.
The table below lists the key variables you can configure to adjust the scraping behavior:
| Variable / Key | Meaning / What You May Change |
|---|---|
targetUrl |
TikTok profile URL you want to scrape. Change for different accounts. |
apiKey |
Your HasData API key. Required for authentication. |
proxyType |
Proxy mode. “residential” is best for TikTok, but you can change to datacenter. |
proxyCountry |
Country for proxy routing (e.g., "DE", "US", "FR"). |
wait |
Delay in milliseconds to let JS render. Increase if TikTok loads slowly. |
You can find the full Python and Node.js scripts in the Python/ and NodeJS/ folders.
Adjust the variables above before running the scrapers to ensure proper data extraction.
This section covers the scripts that fetch all videos uploaded by a TikTok user.
The scraper uses the profile page to extract the secUid, then calls the TikTok item_list API to paginate through all videos.
This allows you to collect structured video metadata including stats, music info, and hashtags.
The table below lists the key variables you can configure:
| Variable / Key | Meaning / What You May Change |
|---|---|
profile_url / profileUrl |
TikTok user profile being scraped. Change to target another account. |
api_key / apiKey |
Your HasData API key. Required. |
proxyCountry |
Country to route residential proxy through ("DE", "US", etc.). |
wait |
Time in ms to allow JS rendering for TikTok page. |
secUid |
Unique internal TikTok user ID (automatically extracted). Do NOT hardcode. |
count |
Videos fetched per request (35 recommended). |
cursor |
Pagination pointer returned by server. |
You can find the full Python and Node.js scripts in the Python/ and NodeJS/ folders.
Adjust these variables before running the scraper to ensure all videos are properly fetched.
This section covers the scripts that download TikTok videos to your local machine.
The downloader reads the structured metadata JSON file produced by the video scraper (videos_clean_full.json) and saves each video as an .mp4 file in the designated folder.
It uses streaming to avoid RAM overload when downloading large files.
The table below lists the key variables you can configure:
| Variable / Key | Meaning / What You May Change |
|---|---|
DOWNLOAD_FOLDER |
Folder where all downloaded .mp4 files are stored. Change if needed. |
videos_clean_full.json |
Input file containing parsed video metadata from previous scripts. |
downloadAddr |
Direct TikTok download link extracted earlier. Used for video download. |
id |
Video ID. Used for naming files (<id>.mp4). |
chunk_size / streaming |
Streaming avoids RAM overload when downloading large video files. |
You can find the full Python and Node.js scripts in the Python/ and NodeJS/ folders.
Make sure to adjust the DOWNLOAD_FOLDER and streaming settings before running the downloader to ensure smooth downloads.
This section covers the scripts that fetch comments from TikTok videos.
The scraper reads a list of video IDs and retrieves all available comments, storing them in a structured JSON file.
Pagination is handled automatically using the TikTok API’s cursor system to ensure all comments are collected.
The table below lists the key variables you can configure:
| Variable / Key | Meaning / What You May Change |
|---|---|
video_ids / videoIds |
List of TikTok video IDs you want to download comments from. |
count |
How many comments to fetch per request (pagination size). |
cursor |
Pagination offset returned by TikTok API (controlled automatically). |
comments.json |
Output file where all parsed comments are saved. |
You can find the full Python and Node.js scripts in the Python/ and NodeJS/ folders.
Adjust the video_ids and count values before running the scraper to control which comments are collected and in what batch size.
This section covers the scripts that perform TikTok searches and extract the resulting videos.
The scraper opens a TikTok search page, listens for the internal search API responses, and collects video metadata in a structured JSON file.
This allows you to automate keyword-based discovery of videos along with author info, hashtags, and stats.
The table below lists the key variables you can configure:
| Variable / Key | Meaning / What You May Change |
|---|---|
keyword |
Search query text for TikTok search. |
search_url / searchUrl |
Search URL generated from keyword. |
api/search/general/full/ |
TikTok internal search results API (captured automatically). |
headless=False / { headless: false } |
Set to True if you want silent browser mode. |
wait_for_timeout(10000) |
Time to allow network requests to finish. Increase if slow. |
search_clean.json |
Output file containing simplified results. |
You can find the full Python and Node.js scripts in the Python/ and NodeJS/ folders.
Adjust the keyword and timeout settings before running the scraper to ensure all relevant search results are captured.
These examples are for educational purposes only. Learn more about the legality of web scraping.
