A comprehensive TikTok scraping library using nodriver (async CDP) with real-time network monitoring, comment/reply extraction, and user data scraping.
Disclaimer: This project is made with AI assistance. It has issues but it works (more or less). You may find weird comments or code.
- CDP Network Capture: Intercepts TikTok's authenticated API requests β no token spoofing needed
- Comment Extraction: Fetch comments + replies via
/api/comment/list/and/api/comment/list/reply/ - User Data Extraction: Videos, reposts, followers, and following lists
- Persistent Login: Log in once, reuse your session across all scripts
- Rate Limiting: Built-in request throttling to avoid blocks
- Language-Independent: Element selection uses HTML structure, not text labels
TTScraper/
βββ TTScraper.py # Main browser automation class
βββ video.py # Video info + comment extraction (CDP)
βββ user.py # User profile, videos, reposts, followers, following
βββ sound.py # Sound/music information
βββ hashtag.py # Hashtag information
βββ comment.py # Comment data structures
βββ helpers.py # Utility functions
βββ browser/
β βββ driver.py # Enhanced driver with config support
β βββ network.py # CDP network monitoring
βββ config/
β βββ settings.py # Configuration classes
βββ core/
β βββ base.py # Base classes
β βββ logging_config.py # Logging setup
β βββ rate_limiting.py # Rate limiter
βββ examples/
β βββ login_setup.py # β First-time login (run this first!)
β βββ extract_user_data.py # User profile + lists extraction
β βββ extract_comments.py # Comment + reply extraction
β βββ extract_video_data.py # Video metadata extraction
β βββ batch_video_extraction.py
βββ browser_profiles/ # Chrome profile data (auto-created)
pip install -r requirements.txtOr manually:
pip install nodriver requests coloramaChrome must be installed. nodriver manages it automatically via CDP.
Before extracting followers, following, or other authenticated data, you must log into TikTok.
Run the login script once:
python examples/login_setup.pyThis opens Chrome on TikTok's login page. Log in manually, then press Enter in the terminal. Your session is saved to browser_profiles/ and reused by all other scripts.
Note: You only need to do this once. Cookies persist across runs.
python examples/extract_user_data.pyYou'll be prompted for:
- TikTok username
- What to extract (profile, videos, reposts, following, followers)
Results are saved to JSON files.
python examples/extract_comments.pyEnter a video URL. The script captures comments via CDP, expands replies, and saves structured output.
import asyncio
from TTScraper import TTScraper
async def main():
scraper = TTScraper()
tab = await scraper.start_browser()
# ... do work ...
scraper.close()
asyncio.run(main())from video import Video
video = Video(url="https://www.tiktok.com/@user/video/123", tab=tab)
# Get video metadata
await video.info()
# Fetch comments + replies via CDP
raw_comments = await video.fetch_comments(tab=tab)
parsed = Video.parse_comments(raw_comments)from user import User
user = User(username="tiktokuser", tab=tab)
# Get profile info
await user.info()
# Fetch videos via CDP (/api/post/item_list/)
raw_videos = await user.fetch_videos(tab=tab)
parsed_videos = User.parse_videos(raw_videos)
# Fetch reposts via CDP (/api/repost/item_list/)
raw_reposts = await user.fetch_reposts(tab=tab)
# Fetch following list (/api/user/list/ scene=21)
raw_following = await user.fetch_following(tab=tab)
parsed_following = User.parse_user_list(raw_following)
# Fetch followers list (/api/user/list/ scene=67)
raw_followers = await user.fetch_followers(tab=tab)
parsed_followers = User.parse_user_list(raw_followers){
"comment_id": "7574851587252718870",
"text": "Great video!",
"username": "user123",
"nickname": "User Name",
"user_id": "6789",
"digg_count": 42,
"reply_count": 3,
"create_time": 1691234567,
"is_author_liked": false,
"replies": [ /* nested reply objects */ ]
}{
"user_id": "123456",
"username": "cooluser",
"nickname": "Cool User",
"sec_uid": "MS4w...",
"verified": true,
"signature": "Bio text here",
"follower_count": 50000,
"following_count": 200,
"video_count": 85
}{
"video_id": "7574851587252718870",
"description": "Check this out! #fyp",
"create_time": 1691234567,
"play_count": 1500000,
"digg_count": 85000,
"comment_count": 1200,
"share_count": 3400,
"duration": 45,
"hashtags": [{"name": "fyp"}]
}By default, Chrome profile data is stored in browser_profiles/ inside the project folder. This is set in config/settings.py:
@dataclass
class BrowserConfig:
user_data_dir: Optional[str] = None # Defaults to <project>/browser_profiles
profile_directory: str = "Profile 1"
headless: bool = Falsescraper = TTScraper(
headless=True,
user_data_dir=r"C:\MyProfiles",
profile_directory="TikTok",
no_sandbox=True,
)Run login_setup.py and log into your TikTok account. Session cookies are saved automatically.
- Make sure the modal/tab is actually opening (check the browser window)
- Try refreshing the page manually
- For reposts: the script will retry up to 3 times with page refresh
- Increase delays between requests
- Use a logged-in session
- Don't run multiple scrapers simultaneously
import logging
logging.basicConfig(level=logging.DEBUG)- Legal: Respect TikTok's Terms of Service. Only extract public content.
- Privacy: Respect data privacy laws (GDPR, etc.)
- Detection: TikTok actively blocks automated access. Use delays and real profiles.
- Changes: TikTok's API endpoints may change without notice.
π Disclaimer: This tool is not affiliated with TikTok. Use responsibly and at your own risk.