Tutorial

How to Automate Local Lead Discovery with a Search API

Build an automated local lead discovery pipeline using Google Maps search via the Scavio API. Find businesses by location, category, and signals.

Automate local lead discovery by querying Google Maps through a search API to find businesses matching your target criteria in specific geographic areas. Manual lead sourcing from Google Maps is tedious and does not scale beyond a few zip codes. This tutorial builds a pipeline that takes a business category and list of locations, queries Scavio's Google search endpoint with local intent, and outputs a structured list of leads with name, address, phone, and website. It covers batch processing, deduplication, and export to CSV.

Prerequisites

  • Python 3.8+ installed
  • requests and csv libraries (both in Python stdlib except requests)
  • A Scavio API key from scavio.dev
  • A list of target locations and business categories

Walkthrough

Step 1: Define target locations and categories

Set up the search matrix of business types and geographic areas you want to prospect.

Python
import os, requests, csv

API_KEY = os.environ['SCAVIO_API_KEY']

CATEGORIES = ['plumber', 'hvac contractor', 'roofing company']
LOCATIONS = ['Austin TX', 'Denver CO', 'Nashville TN']

def build_queries(categories: list, locations: list) -> list:
    queries = []
    for cat in categories:
        for loc in locations:
            queries.append(f'{cat} in {loc}')
    return queries

print(f'Generated {len(build_queries(CATEGORIES, LOCATIONS))} search queries')

Step 2: Search and extract local business data

Query Scavio with local intent and parse business listings from the results.

Python
def search_local_leads(query: str) -> list:
    resp = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': API_KEY},
        json={'platform': 'google', 'query': query}, timeout=15)
    resp.raise_for_status()
    data = resp.json()
    leads = []
    for r in data.get('local_results', data.get('organic_results', [])):
        leads.append({
            'name': r.get('title', ''),
            'address': r.get('address', ''),
            'phone': r.get('phone', ''),
            'website': r.get('link', ''),
            'rating': r.get('rating', ''),
            'query': query,
        })
    return leads

Step 3: Deduplicate across queries

Remove duplicate businesses that appear in multiple queries by matching on name and phone number.

Python
def deduplicate_leads(all_leads: list) -> list:
    seen = set()
    unique = []
    for lead in all_leads:
        key = (lead['name'].lower().strip(), lead.get('phone', ''))
        if key not in seen:
            seen.add(key)
            unique.append(lead)
    return unique

def collect_all_leads(queries: list) -> list:
    all_leads = []
    for q in queries:
        leads = search_local_leads(q)
        all_leads.extend(leads)
        print(f'{q}: {len(leads)} leads')
    return deduplicate_leads(all_leads)

Step 4: Export to CSV

Write the deduplicated leads to a CSV file ready for import into your CRM or outreach tool.

Python
def export_csv(leads: list, filename: str = 'local_leads.csv'):
    if not leads:
        print('No leads to export')
        return
    fields = ['name', 'address', 'phone', 'website', 'rating', 'query']
    with open(filename, 'w', newline='') as f:
        writer = csv.DictWriter(f, fieldnames=fields)
        writer.writeheader()
        writer.writerows(leads)
    print(f'Exported {len(leads)} leads to {filename}')

queries = build_queries(CATEGORIES, LOCATIONS)
leads = collect_all_leads(queries)
export_csv(leads)

Python Example

Python
import requests, os, csv
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}

def find_leads(category, location):
    data = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
        json={'platform': 'google', 'query': f'{category} in {location}'}).json()
    return [{'name': r.get('title', ''), 'url': r.get('link', '')}
        for r in data.get('local_results', data.get('organic_results', []))]

for lead in find_leads('plumber', 'Austin TX'):
    print(lead['name'])

JavaScript Example

JavaScript
const H = {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};
async function findLeads(category, location) {
  const r = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: H,
    body: JSON.stringify({platform: 'google', query: `${category} in ${location}`})
  });
  const data = await r.json();
  return (data.local_results || data.organic_results || []).map(r => ({name: r.title, url: r.link}));
}
findLeads('plumber', 'Austin TX').then(leads => leads.forEach(l => console.log(l.name)));

Expected Output

JSON
A CSV file of deduplicated local business leads with name, address, phone, website, and rating, collected from Google Maps results across multiple locations.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.8+ installed. requests and csv libraries (both in Python stdlib except requests). A Scavio API key from scavio.dev. A list of target locations and business categories. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Build an automated local lead discovery pipeline using Google Maps search via the Scavio API. Find businesses by location, category, and signals.