DEV Community

Cover image for Build an Automated Reddit Lead Generation Bot in Python
Olamide Olaniyan
Olamide Olaniyan

Posted on

Build an Automated Reddit Lead Generation Bot in Python

Reddit is a goldmine for high-intent leads. Every day, thousands of people post questions like:

  • "What's the best alternative to [Your Competitor]?"
  • "How do I solve [Problem Your SaaS Solves]?"
  • "Looking for recommendations for a [Your Product Category] tool."

If you can find these posts within minutes of them going live, you can jump into the comments and naturally recommend your product.

In this tutorial, I'll show you how to build a Python bot that monitors Reddit for high-intent buying keywords, filters out the noise, and delivers warm leads straight to your terminal or a CSV file.

The Problem with the Official Reddit API

Reddit recently changed its API pricing, making it incredibly expensive for developers to pull data at scale. Furthermore, dealing with OAuth tokens just to run a simple search script is a massive headache.

Instead, we'll use the SociaVault API, which provides a simple, affordable REST endpoint to search Reddit without needing Reddit API keys or dealing with rate limits.

Prerequisites

  • Python 3.8+
  • requests library (pip install requests)
  • pandas library (pip install pandas)
  • A SociaVault API key (Get 1,000 free credits at sociavault.com)

Step 1: Define Your Buying Intent Keywords

First, we need to define the queries that indicate someone is looking to buy. Let's pretend we are building a lead gen bot for an Email Marketing SaaS.

import requests
import pandas as pd
import time

API_KEY = 'your_sociavault_api_key'
BASE_URL = 'https://api.sociavault.com/v1/reddit/search'

headers = {
    'Authorization': f'Bearer {API_KEY}',
    'Content-Type': 'application/json'
}

# High-intent search queries
QUERIES = [
    "alternative to mailchimp",
    "best email marketing tool",
    "how to send cold emails",
    "looking for an email sender"
]
Enter fullscreen mode Exit fullscreen mode

Step 2: Fetching the Leads

We'll loop through our queries and hit the SociaVault Reddit Search endpoint. We want to sort by "new" so we only get the freshest leads.

def fetch_reddit_leads(queries):
    all_leads = []

    for query in queries:
        print(f"Searching Reddit for: '{query}'...")

        try:
            response = requests.get(
                BASE_URL,
                headers=headers,
                params={
                    'query': query,
                    'sort': 'new', # Get the most recent posts
                    'limit': 10    # Top 10 recent posts per query
                }
            )

            if response.status_code == 200:
                posts = response.json().get('data', [])

                for post in posts:
                    all_leads.append({
                        'Query': query,
                        'Title': post.get('title'),
                        'Subreddit': post.get('subreddit'),
                        'Author': post.get('author'),
                        'URL': f"https://reddit.com{post.get('permalink')}",
                        'Upvotes': post.get('score'),
                        'Comments': post.get('num_comments'),
                        'Created_UTC': post.get('created_utc')
                    })
            else:
                print(f"Error fetching {query}: {response.text}")

        except Exception as e:
            print(f"Request failed: {e}")

        # Be polite to the API
        time.sleep(1)

    return all_leads
Enter fullscreen mode Exit fullscreen mode

Step 3: Filtering and Exporting

Not every post is a good lead. We might want to filter out posts that already have too many comments (where our reply would get buried) or posts from irrelevant subreddits.

def process_and_export_leads(leads):
    if not leads:
        print("No leads found.")
        return

    df = pd.DataFrame(leads)

    # Filter out posts with more than 20 comments (too crowded)
    df = df[df['Comments'] < 20]

    # Drop duplicates in case multiple queries found the same post
    df = df.drop_duplicates(subset=['URL'])

    print(f"\nFound {len(df)} high-quality leads!")

    # Display the top leads in the terminal
    for index, row in df.head(5).iterrows():
        print("-" * 50)
        print(f"Subreddit: r/{row['Subreddit']}")
        print(f"Title: {row['Title']}")
        print(f"Link: {row['URL']}")

    # Export to CSV for your sales team
    filename = f"reddit_leads_{int(time.time())}.csv"
    df.to_csv(filename, index=False)
    print(f"\nExported all leads to {filename}")

# Run the bot
if __name__ == "__main__":
    print("Starting Reddit Lead Gen Bot...")
    leads = fetch_reddit_leads(QUERIES)
    process_and_export_leads(leads)
Enter fullscreen mode Exit fullscreen mode

The Output

When you run the script, you'll get a clean list of people actively looking for your solution:

Starting Reddit Lead Gen Bot...
Searching Reddit for: 'alternative to mailchimp'...
Searching Reddit for: 'best email marketing tool'...
Searching Reddit for: 'how to send cold emails'...
Searching Reddit for: 'looking for an email sender'...

Found 14 high-quality leads!
--------------------------------------------------
Subreddit: r/Entrepreneur
Title: Mailchimp just doubled my bill. What's a good alternative for 10k subs?
Link: https://reddit.com/r/Entrepreneur/comments/...
--------------------------------------------------
Subreddit: r/SaaS
Title: Best email marketing tool for a bootstrapped startup?
Link: https://reddit.com/r/SaaS/comments/...
--------------------------------------------------
Exported all leads to reddit_leads_1708953421.csv
Enter fullscreen mode Exit fullscreen mode

Next Steps: Automation

To make this a true "bot", you can:

  1. Deploy this script to a cheap VPS (like DigitalOcean or AWS EC2).
  2. Set up a cron job to run it every hour.
  3. Instead of saving to a CSV, modify the script to send a Slack webhook or an email notification whenever a new lead is found.

By using SociaVault, you bypass the Reddit API pricing changes and OAuth complexities. You just make a simple GET request and get clean JSON data back.

Get your free API key at SociaVault.com and start generating leads on autopilot today.

Top comments (0)