Tutorial: Build a TikTok Lead Generation Extractor in Python

TikTok is no longer just an entertainment platform; it has evolved into a massive data goldmine for B2B Sales and Outreach campaigns. Many TikTokers, local shops, agencies, and small businesses drop their business email in their bio (signature) to receive booking inquiries and brand deals.

Instead of manually scrolling through profiles on your phone to copy each email, this tutorial will show you how to fully automate the process. We will build a tool to scrape bio data in bulk and extract emails using Regex with Python, powered by a blazing-fast API.


šŸš€ Core Tool: TikTok User Info API

To extract data quickly without dealing with fake accounts, cookie management, or complex proxies, we'll use a specialized Actor on the Apify platform.

Try the API Here

1. How It Works (The Logic)

  1. Start with a list of dozens or hundreds of TikTok usernames within a specific niche (e.g., parenting, fashion, fitness).
  2. Use Python to call the API to scrape the profile data in bulk and in parallel at incredible speeds (~100 results in just 30 seconds).
  3. Utilize Python's Regular Expressions (Regex) library to automatically scan the signature data field and extract valid email formats.
  4. Export the collected list of emails to fuel your Cold Email campaigns.

2. Setting Up Your Environment

You need to install the apify-client library so your Python script can seamlessly communicate with Apify's API. Open your Terminal or Command Prompt and run:

pip install apify-client

Note: You will need to sign up for a free Apify account and grab your API Token from Settings > Integrations.

3. The Python Code: TikTok Lead Extractor

Create a file named tiktok_lead_gen.py and paste the following code. This snippet includes the exact Regex pattern needed to reliably identify emails.

import re
import json
from apify_client import ApifyClient

# 1. Initialize the client with your API Token
# Replace 'YOUR_APIFY_TOKEN' with your actual token
client = ApifyClient("YOUR_APIFY_TOKEN")

# Use the Actor developed by the Novi team
actor_id = "novi/tiktok-user-info-api"

# The list of channels you want to scrape (Can be loaded from a TXT/CSV file)
run_input = {
    "usernames": [
        "vtv24news",
        "pewpew.studio",
        "hasaki.vn" 
        # Add your target usernames here
    ]
}

print("šŸš€ Starting bulk profile scraping on TikTok...")

# 2. Call the API and wait for the results
run = client.actor(actor_id).call(run_input=run_input)
print("✅ Scraping successful! Analyzing Bios to find emails...")

# Get the ID of the returned dataset
dataset_id = run.get("defaultDatasetId")

# 3. Standard Regex pattern to catch email formats
email_pattern = r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'

extracted_leads = []

# Iterate through each scraped profile
for item in client.dataset(dataset_id).iterate_items():
    username = item.get("uniqueId")
    bio_text = item.get("signature", "")
    follower_count = item.get("followerCount", 0)
    
    # Search for all emails within the Bio string
    emails_found = re.findall(email_pattern, bio_text)
    
    # If at least 1 email is found, save it to the Lead list
    if emails_found:
        extracted_leads.append({
            "Username": username,
            "Followers": follower_count,
            "Emails": list(set(emails_found)), # Remove duplicate emails if any
            "Original_Bio": bio_text.replace('\n', ' ')
        })

# 4. Print the final results
print(f"\nšŸŽÆ Found {len(extracted_leads)} potential leads:\n")
print(json.dumps(extracted_leads, indent=4, ensure_ascii=False))

# Next Step: You can use pandas to export 'extracted_leads' to an Excel or CSV file!

4. Scaling Your System

The script above provides an extremely solid foundation. From here, you can easily expand its capabilities:

  • Vetting Tool Filter: Add an if follower_count > 100000: condition to only extract emails from large KOC/KOL channels.
  • Extract Phone Numbers: Write an additional Regex pattern to find phone numbers (e.g., checking for specific area codes and lengths) to diversify your outreach channels (SMS/Telesales).
  • Category Checks: Combine keyword analysis in the Bio to categorize leads (e.g., if the Bio contains "apparel" or "fashion", classify them into the Fashion segment).

Conclusion

Building a potential customer data collection tool has never been easier when you have an accurate API at your fingertips. By eliminating the burden of dealing with the platform's anti-bot measures, you can focus entirely on processing your data and refining your business logic.

šŸ‘‰ Don't miss out on this optimized solution. Grab your API Key and start running the script today:
Use the TikTok User Info API Now

Comments