Skip to content
ajendrasPublic

About

CLI to scrape and enrich targeted business leads from Google Search, Maps, Yelp and directories

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

41 Commits

Folders and files

Repository files navigation

LeadMine

Target any niche & location Β· Extracts contacts & websites Β· Clean CSVs, zero SaaS fees

License TypeScript Stars CI Last commit PRs welcome

CLI to scrape and enrich targeted business leads from Google Search, Maps, Yelp, YellowPages, Crunchbase and directories

✨ Features β€’ ⚑ Quick start β€’ 🧰 Usage β€’ 🧩 Architecture β€’ πŸ“ Roadmap β€’ 🀝 Contributing

✨ Why LeadMine?

Freelancers, agencies and sales teams burn hours hunting prospects on Google and Maps. Commercial tools are pricey, opaque and rate-limited. LeadMine gives full control with a transparent, self-hosted CLI that pulls public data for any category and locale.

  • Self-hosted & transparent β€” full visibility into every request, no vendor lock-in or surprise billing
  • Polite by design β€” built-in rate limiting, random delays, user-agent rotation and stealth via Playwright
  • Multi-source enrichment β€” Google Maps, organic Search, Yelp, YellowPages and Crunchbase with automatic website crawling for emails and missing phones
  • Clean, flexible exports β€” deduplicated leads written to CSV, JSON, XLSX or directly to Google Sheets

🎬 Demo

LeadMine demo

πŸš€ Features

πŸ—ΊοΈ Maps Scraper
Pulls name, address, phone, rating and website from Google Maps results using Playwright
πŸ”Ž Search Leads
Extracts organic Google results and linked contact pages for broader web leads
πŸ“ Yelp Support
Scrapes business listings from Yelp with fallback when Maps data is thin
🟨 YellowPages & Crunchbase
Additional US directory and startup ecosystem sources with profile enrichment
πŸ“€ Smart Export
Writes clean CSV, JSON or XLSX with configurable columns, deduplication and --append support for CSV/JSON
πŸ”§ Contact Enricher
Visits websites to discover email patterns, social links and missing phones
πŸ“§ Email Verification
Filters out emails from known disposable providers using a local domain list (configurable)
⏱️ Polite Crawling
Per-source rate-limit presets (maps: 6rpm, search: 10rpm, etc.), random delays, exponential backoff on 429/blocks, user-agent rotation and stealth to reduce blocks
🎯 Targeted Filters
Category, location, rating, review count and keyword filters for high-quality leads
🧠 Local LLM Scoring
Uses Ollama to score leads on relevance to your category and budget signals with configurable minScore filter (local only, no data leaves your machine)
πŸ“Š Google Sheets Export
Direct write to Google Sheets via service account (no OAuth, no extra fees)
πŸ”„ Proxy Rotation + Residential
Configurable proxy lists with automatic rotation; native support for residential proxy providers (Smartproxy, Oxylabs, Bright Data gateway URLs)
πŸͺ„ Interactive Wizard
Guided first-time setup that creates ~/.leadmine/config.json and runs a sample scrape
🐳 Docker Support
Official image with pre-bundled Chromium β€” perfect for servers, CI/CD and headless deployments with zero extra setup

πŸ“¦ Installation

Requirements: Node.js >= 18.0.0 (see engines in package.json). Ollama must be installed separately for LLM scoring. Docker is optional but recommended for server use.

npm install -g lead-mine

The CLI is available immediately as lead-mine. For local development:

git clone https://github.com/ajendras/lead-mine.git
cd lead-mine
npm install
npm run build

🐳 Docker

LeadMine ships a Dockerfile that produces a ready-to-run image based on the official Playwright Docker image. Chromium and all system dependencies are pre-bundled, eliminating download steps and making it ideal for servers, headless environments, and CI pipelines.

# Build the image (includes build step via prepare script)
npm run docker:build
# or
docker build -t lead-mine .

Usage examples

# Interactive wizard (recommended first run)
docker run -it --rm lead-mine wizard

# Standard scrape with output mounted to host
docker run --rm \
  -v $(pwd):/data \
  -v ~/.leadmine:/root/.leadmine \
  lead-mine scrape \
    --category="plumbers" \
    --location="Portland, OR" \
    --limit=30 \
    --output=/data/leads.csv \
    --enrich \
    --verify-emails

# Search source with LLM scoring (Ollama must be available on host; use --network=host if needed)
docker run --rm \
  -v $(pwd):/data \
  -v ~/.leadmine:/root/.leadmine \
  lead-mine scrape \
    --source=search \
    --query="HVAC companies near Austin TX" \
    --output=/data/results.csv \
    --enrich \
    --use-llm-scoring

Notes

  • The image automatically skips Playwright browser downloads.
  • Mount ~/.leadmine to persist configuration, service-account keys, and cached data.
  • For Ollama scoring inside Docker, run Ollama on the host and add --network=host (or link containers).
  • The entrypoint is the lead-mine binary; any CLI command works.
  • Image size is ~1.2 GB (Playwright base); extend it for custom needs.

⚑ Quick start

Run the interactive wizard (recommended for first-time users):

lead-mine wizard

It will ask a few questions, create a config file with your preferences, and run a sample scrape so you can see results immediately.

import { loadConfig, scrapeMaps, scrapeYellowPages, saveLeads, exportToSheets, RATE_LIMIT_PRESETS } from 'lead-mine';

const config = await loadConfig();

// Config values are merged; explicit options override them
const leads = await scrapeYellowPages('plumbers', 'Portland, OR', {
  ...config,
  limit: 30,
  enrich: true,
  verifyEmails: true,
  useLLMScoring: true,
  ollamaModel: 'llama3.1',
  rpm: 12,
  proxy: 'http://user:pass@residential.provider:22222',
});

await saveLeads(leads, 'leads.csv');
// or export directly to Sheets
// await exportToSheets(leads, '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms');
console.log(`Captured ${leads.length} leads`);

🧰 Usage

Interactive Wizard (recommended for first-time users)

lead-mine wizard

The wizard guides you through choosing a default source, category, location, enrichment settings and more. It creates ~/.leadmine/config.json and runs a sample scrape so you can see results right away.

Run the CLI (most common workflow). The CLI automatically loads defaults from ~/.leadmine/config.json if it exists. Flags override config values.

lead-mine scrape --category="plumbers" --location="Portland, OR" --limit=30 --output=leads.csv --verify-emails

Search-focused run with enrichment:

lead-mine scrape --source=search --query="HVAC companies near Austin TX" --output=results.json --enrich --verify-emails

LLM scoring (requires Ollama running locally with a model pulled):

lead-mine scrape --category="plumbers" --location="Portland, OR" --use-llm-scoring --ollama-model=llama3.1 --min-score=6 --limit=15

Yelp fallback when Maps coverage is thin:

lead-mine scrape --source=yelp --category="roof repair" --location="Seattle, WA" --limit=15

YellowPages and Crunchbase examples:

lead-mine scrape --source=yellowpages --category="electricians" --location="Chicago, IL" --limit=25
lead-mine scrape --source=crunchbase --query="fintech startups" --limit=15 --enrich --verify-emails

Google Sheets direct export (see setup below):

lead-mine scrape --category="plumbers" --location="Portland, OR" \
  --sheets=1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms --limit=20 --enrich

Residential proxy example (rotates IPs via provider gateway):

lead-mine scrape --category="lawyers" --location="New York, NY" --limit=50 \
  --proxy="http://youruser-zone-residential:yourpass@gate.smartproxy.com:7000"

Multiple proxies (CLI rotates through them):

lead-mine scrape --category="plumbers" --location="Portland, OR" \
  --proxy http://proxy1.example.com:8080 http://proxy2.example.com:8080

Rate-limit override (uses preset for source otherwise):

lead-mine scrape --category="plumbers" --location="Portland, OR" --rpm=8

Append mode (CSV/JSON only)

lead-mine scrape --category="plumbers" --location="Portland, OR" --output=leads.csv --append

Docker usage (see Docker section above for full details):

docker run --rm \
  -v $(pwd):/data \
  -v ~/.leadmine:/root/.leadmine \
  lead-mine scrape --category="plumbers" --location="Portland, OR" --output=/data/leads.csv --enrich

Programmatic usage with custom options (see src/index.ts):

import { loadConfig, scrapeYellowPages, scrapeCrunchbase, saveLeads, exportToSheets, scoreLeadWithOllama, withRateLimit, randomDelay, processWithConcurrency, RATE_LIMIT_PRESETS } from 'lead-mine';

const config = await loadConfig();

const leads = await scrapeYellowPages('coffee shops', 'Portland, OR', {
  ...config,
  limit: 25,
  minRating: 4.0,
  minScore: 6,
  enrich: true,
  verifyEmails: true,
  useLLMScoring: true,
  ollamaModel: 'llama3.1',
  proxy: ['http://proxy1:8080', 'http://proxy2:8080'],
  concurrency: 3,
});

await saveLeads(leads, 'coffee-leads.csv');
// append example:
await saveLeads(leads, 'coffee-leads.csv', true);
// or
// await exportToSheets(leads, 'your-spreadsheet-id-here', { sheetName: 'PortlandLeads' });
console.log(`Captured ${leads.length} leads`);
Advanced: custom rate-limit and headless control
import { loadConfig, scrapeCrunchbase, processWithConcurrency, RATE_LIMIT_PRESETS } from 'lead-mine';

const config = await loadConfig();

const leads = await scrapeCrunchbase('AI companies', {
  ...config,
  limit: 20,
  headless: false,
  enrich: true,
  verifyEmails: true,
  useLLMScoring: true,
  concurrency: 4,
});

// Example of direct parallel processing of custom items using preset
const processed = await processWithConcurrency(
  leads,
  async (lead) => {
    // custom per-lead logic
    return lead;
  },
  3,
  { source: 'crunchbase' } // or RATE_LIMIT_PRESETS.crunchbase.rpm
);

Ollama Setup for LLM Scoring

  1. Install Ollama from https://ollama.com
  2. Start the server: ollama serve
  3. Pull a model: ollama pull llama3.1 (or mistral, phi3, gemma2:9b)
  4. Use --use-llm-scoring (or set useLLMScoring: true in config). Scoring is rate-limited and runs locally.

πŸ”§ Configuration

Configuration File

The easiest way to create your configuration is by running lead-mine wizard. It will interactively ask questions and write a ready-to-use ~/.leadmine/config.json.

LeadMine automatically loads defaults from ~/.leadmine/config.json (created manually or via the wizard). Any ScrapeOptions (including source, category and location) can be set here. Command-line flags and programmatic options take precedence. If rpm is omitted, a polite preset for the chosen source is used automatically.

Example ~/.leadmine/config.json:

{
  "source": "maps",
  "category": "plumbers",
  "location": "Portland, OR",
  "limit": 30,
  "enrich": true,
  "verifyEmails": true,
  "useLLMScoring": true,
  "ollamaModel": "llama3.1",
  "headless": true,
  "minRating": 4.0,
  "minScore": 5.0,
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
  "proxy": "http://user:pass@zproxy.lumproxy.com:22222",
  "googleSheets": {
    "spreadsheetId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
    "sheetName": "Leads"
  }
}
Option Default Description
source maps Default scraper source (maps, search, yelp, yellowpages, crunchbase)
category β€” Default business category or search term
location Portland, OR Default geographic location for directory scrapers
limit 20 Maximum number of leads to return (ScrapeOptionsSchema)
enrich true Visit websites to discover emails and metadata
verifyEmails false Filter extracted emails against a local list of known disposable domains; sets emailVerified on Lead records
useLLMScoring false Enable local LLM scoring via Ollama for relevance (to target) and budget signals
ollamaModel llama3.1 Ollama model name (must be pulled locally; llama3.1, mistral, phi3 supported)
headless true Run browser without GUI (--no-headless to disable)
rpm varies by source Requests per minute. Each source has a polite preset (maps: 6, search: 10, yelp: 15, yellowpages: 25, crunchbase: 12). Overridable via flag/config. Exponential backoff is applied automatically on rate-limit or block errors.
minRating β€” Filter leads by minimum rating (0–5)
minScore 0 Minimum relevance score (0-10) to keep after LLM scoring (only applied if useLLMScoring: true)
userAgent β€” Override default stealth user agent
proxy β€” Single proxy URL or array of URLs for rotation. Residential proxies supported via provider gateway (e.g. http://user-zone-resi:pass@gate.smartproxy.com:7000). Rotates automatically across browser sessions.
googleSheets.spreadsheetId β€” Spreadsheet ID for direct Google Sheets export
googleSheets.sheetName Leads Target sheet/tab name inside the spreadsheet
googleSheets.serviceAccountKeyPath ~/.leadmine/service-account.json Path to service account JSON key file
concurrency 3 Max parallel operations for enrichment/scoring (used by processWithConcurrency)
append false Append leads to existing CSV/JSON file (instead of overwriting). Other formats always overwrite.

RateLimitOptions (used by withRateLimit, processWithConcurrency and internally by all scrapers) can be supplied as a plain number (treated as RPM) or an object:

{
  rpm?: number;           // requests per minute
  backoffFactor?: number; // multiplier on 429 errors (default 1.5)
  maxDelayMs?: number;    // cap on backoff delay (default 45000)
  source?: ScrapeSource;  // used for independent per-source timers
}

All options are validated by ScrapeOptionsSchema (Zod) in src/types.ts.

When using the Docker image, the same config file is loaded from the mounted ~/.leadmine (or /root/.leadmine) volume.

πŸ”‘ Google Sheets Setup

  1. Go to the Google Cloud Console, create/select a project.
  2. Enable the Google Sheets API under APIs & Services > Library.
  3. Navigate to IAM & Admin > Service Accounts > Create Service Account.
  4. Grant the Editor role, then create a key (JSON format) and download it.
  5. Copy the downloaded JSON to ~/.leadmine/service-account.json (or set googleSheets.serviceAccountKeyPath).
  6. Open your target Google Sheet β†’ Share β†’ add the client_email value from the JSON file (ends in @gserviceaccount.com) with Editor permissions.

LeadMine will now write leads directly to the sheet using the service account (no user login required). The first row becomes a header; existing data is overwritten.

🧩 Architecture

flowchart TD
    CLI[cli.ts<br>Commander.js flags] --> Index[src/index.ts<br>orchestrator]
    Index --> Maps[src/scrapers/maps.ts<br>Playwright scroll + panel extraction]
    Index --> Search[src/scrapers/search.ts<br>organic results + snippet parsing]
    Index --> Yelp[src/scrapers/yelp.ts<br>list + detail page visits]
    Index --> YellowPages[src/scrapers/yellowpages.ts<br>list extraction with stable classes]
    Index --> Crunchbase[src/scrapers/crunchbase.ts<br>profile scraping + website extraction]
    Maps & Search & Yelp & YellowPages & Crunchbase --> Throttle[src/utils/throttle.ts<br>randomDelay + withRateLimit (presets + backoff)]
    Index --> Enrich[enricher.ts<br>launchStealthBrowser + regex extraction + disposable checker + Ollama scoring]
    Enrich --> Browser[src/utils/browser.ts<br>stealth Chromium + proxy rotator]
    Index --> Dedup[deduplicateLeads<br>name+address+website key]
    Index --> Parallel[processWithConcurrency<br>respects concurrency limit via batches]
    Dedup --> Export[exporter.ts<br>csv-writer / xlsx / JSON / Google Sheets API]
    Export --> FS[CSV / JSON / XLSX output]
    Export --> Google[Google Sheets via service account (googleapis)]
    style Index fill:#d9c2a3,stroke:#3f2a1e
Loading

src/index.ts coordinates scraping, enrichment, deduplication and export. All scrapers return a uniform Lead[] shape defined in src/types.ts. Browser sessions are created fresh per scrape/enrichment to maintain stealth. Proxy rotation (including residential gateways) is handled centrally in browser.ts.

πŸ“ Project structure

.
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts          # Public API: scrapeMaps(), scrapeSearch(), scrapeYelp(), scrapeYellowPages(), scrapeCrunchbase(), saveLeads(), exportToSheets(), loadConfig(), saveConfig(), scoreLeadWithOllama(), withRateLimit(), processWithConcurrency(), RATE_LIMIT_PRESETS
β”‚   β”œβ”€β”€ cli.ts            # Commander.js command definition with all flags + interactive wizard
β”‚   β”œβ”€β”€ config.ts         # loadConfig(), saveConfig() + CONFIG_PATH/SERVICE_ACCOUNT_PATH for ~/.leadmine/
β”‚   β”œβ”€β”€ types.ts          # Lead interface, ScrapeOptions (incl. googleSheets), RateLimitPreset + RATE_LIMIT_PRESETS, Zod schema, ExportFormat
β”‚   β”œβ”€β”€ enricher.ts       # enrichLead() + extractEnrichedInfo (mailto, regex, tel:) + isDisposableEmail() + scoreLeadWithOllama()
β”‚   β”œβ”€β”€ exporter.ts       # exportLeads() + new exportToSheets() using googleapis
β”‚   β”œβ”€β”€ scrapers/
β”‚   β”‚   β”œβ”€β”€ maps.ts       # scrapeGoogleMaps() + extractFromSidePanel
β”‚   β”‚   β”œβ”€β”€ search.ts     # scrapeGoogleSearch() + extractContactInfo
β”‚   β”‚   β”œβ”€β”€ yelp.ts       # scrapeYelp() + extractYelpDetail
β”‚   β”‚   β”œβ”€β”€ yellowpages.ts # scrapeYellowPages() + extractYellowPagesResults
β”‚   β”‚   └── crunchbase.ts # scrapeCrunchbase() + extractCrunchbaseResults/Profile
β”‚   └── utils/
β”‚       β”œβ”€β”€ browser.ts    # launchStealthBrowser() + setProxies() + rotation
β”‚       └── throttle.ts   # randomDelay(), withRateLimit() (now with presets + backoff)
β”œβ”€β”€ tests/
β”‚   └── scrapers.test.ts  # Vitest mocks + fixture tests for parsers, dedup, export, sheets
β”œβ”€β”€ playwright.config.ts  # Headless config, user-agent, timeouts
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ Dockerfile            # Official image with bundled Chromium (Playwright base)
└── package.json          # bin:"lead-mine", scripts, dependencies

πŸ§ͺ Testing

npm test

Runs the Vitest suite in tests/scrapers.test.ts. Covers mocked scraper fixtures, Lead shape validation, deduplication logic, enrichment fallbacks, throttle utilities (randomDelay, withRateLimit with presets and backoff), export formats (CSV/JSON/XLSX), the new exportToSheets() path (including error cases for missing service account key), CLI option parsing, the loadConfig()/saveConfig() helpers, new proxy rotation behaviour, the YellowPages/Crunchbase parsers, the new disposable email verification logic, local LLM scoring with mocked Ollama responses, the interactive wizard, processWithConcurrency (respects concurrency limit and calls rate limiter), and append mode for CSV/JSON.

πŸ“ Roadmap

  • v0.1.0 β€” first release: Maps Scraper, Search Leads, Yelp Support, Smart Export
  • Add configuration file support (~/.leadmine/config.json)
  • Implement proxy rotation and residential proxy interface
  • Add more directory scrapers (YellowPages, Crunchbase)
  • Email verification step using disposable checker or SMTP
  • Interactive wizard mode for first-time users
  • Google Sheets direct export via service account
  • Local LLM lead scoring with Ollama (relevance, budget signals)
  • Parallel browser contexts with worker pool
  • HTML report generator with embedded map previews
  • Docker image with bundled Chromium for server use
  • CRM import templates (HubSpot CSV, Salesforce)
  • Rate-limit presets per source with exponential backoff
  • Add --append flag to saveLeads() allowing CSV/JSON append instead of overwrite
  • Implement configurable minScore threshold in ScrapeOptions to filter LLM-scored leads
  • Add actionable troubleshooting suggestions to CLI error output (blocks, missing Ollama, proxy failures)
  • Expand scrapers.test.ts with mocked end-to-end tests for wizard + config roundtrip
  • Document scraper extension pattern and template in CONTRIBUTING.md with new source checklist
  • Support loading proxy list from text file (--proxy-file) in config.ts and browser utils
  • Add --dry-run mode that prints planned queries, limits and estimated cost without launching browsers
  • Update Docker image with multi-stage build and non-root user for smaller size and security

πŸ€– This roadmap is worked through continuously β€” ideas and PRs welcome!

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md and follow our Code of Conduct. Good-first-issue PRs around new directory sources, improved enrichment patterns, or additional export columns are especially appreciated.

πŸ“„ License

MIT Β© ajendras. See LICENSE for details.

⭐ Star history

Star history

If LeadMine saves you time, a ⭐ helps others find it.

Made with ❀️ by Ajendra

About

CLI to scrape and enrich targeted business leads from Google Search, Maps, Yelp and directories

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages