通过搜索 API 查询 Google 地图,自动发现本地潜在客户,以查找特定地理区域中符合您的目标标准的企业。从 Google 地图手动寻找潜在客户非常繁琐,而且范围仅限于几个邮政编码。本教程构建了一个管道,该管道采用业务类别和位置列表,使用本地意图查询 Scavio 的 Google 搜索端点,并输出包含姓名、地址、电话和网站的结构化潜在客户列表。它涵盖批处理、重复数据删除和导出到 CSV。
前置条件
- 已安装 Python 3.8+
- requests 和 csv 库(除了 requests 之外,都在 Python stdlib 中)
- 来自 scavio.dev 的 Scavio API 密钥
- 目标地点和业务类别列表
操作指南
步骤 1: 定义目标位置和类别
设置您想要寻找的业务类型和地理区域的搜索矩阵。
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')步骤 2: 搜索并提取本地商业数据
具有本地意图的 Scavio 查询并从结果中解析业务列表。
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步骤 3: 跨查询去重
通过匹配姓名和电话号码,删除多个查询中出现的重复企业。
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)步骤 4: 导出为 CSV
将经过重复数据删除的潜在客户写入 CSV 文件,以便导入到您的 CRM 或外展工具中。
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 示例
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 示例
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)));预期输出
A CSV file of deduplicated local business leads with name, address, phone, website, and rating, collected from Google Maps results across multiple locations.