r/coldemail 线程要求提供从在 Google 地图上查找企业到发送 WhatsApp 消息的完整管道。本教程涵盖了完整的循环:按类别和位置搜索、提取电话号码、生成个性化消息以及创建点击聊天链接。所有数据均来自一个 API。
前置条件
- Scavio API 密钥
- Python 3.8+
- WhatsApp 企业帐户或个人 WhatsApp
操作指南
步骤 1: 按类别批量搜索Google地图
搜索整个城市的多个类别。
Python
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}
def batch_maps_search(categories, city):
all_leads = []
for cat in categories:
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=H,
json={'platform': 'google', 'query': f'{cat} in {city}',
'type': 'maps'}).json()
for b in data.get('local_results', []):
b['category'] = cat
all_leads.append(b)
return all_leads
categories = ['restaurant', 'dentist', 'gym', 'salon']
leads = batch_maps_search(categories, 'Miami FL')步骤 2: 清理并验证电话号码
设置 WhatsApp 电话号码的格式(需要国家/地区代码)。
Python
import re
def clean_phone(phone, country_code='1'):
if not phone:
return None
digits = re.sub(r'\D', '', phone)
if len(digits) == 10:
digits = country_code + digits
if len(digits) < 11:
return None
return digits
def extract_leads_with_phones(businesses):
valid = []
for b in businesses:
phone = clean_phone(b.get('phone'))
if phone:
valid.append({
'name': b.get('title', ''),
'phone': phone,
'category': b.get('category', ''),
'rating': b.get('rating'),
'address': b.get('address', ''),
})
return valid步骤 3: 生成特定类别的 WhatsApp 消息
不同的业务类型有不同的模板。
Python
templates = {
'restaurant': 'Hi! I saw {name} has great reviews ({rating} stars). '
'I help restaurants increase online orders with a simple website update. '
'Worth a quick chat?',
'dentist': 'Hi! I came across {name} and noticed you serve the {area} area. '
'I help dental practices get more patients through online visibility. '
'Can I send over a quick case study?',
'default': 'Hi! I found {name} on Google Maps ({rating} stars -- impressive). '
'I help local businesses like yours grow their online presence. '
'Would you be open to a quick chat?'
}
def generate_wa_link(lead, service_templates=templates):
template = service_templates.get(lead['category'], service_templates['default'])
msg = template.format(name=lead['name'], rating=lead.get('rating', 'great'),
area=lead.get('address', '').split(',')[0] if lead.get('address') else 'your')
encoded = requests.utils.quote(msg)
return f"https://wa.me/{lead['phone']}?text={encoded}"步骤 4: 导出完整的管道输出
包含所有潜在客户数据和 WhatsApp 链接的 CSV。
Python
import csv
def export_pipeline(leads, filename='whatsapp_pipeline.csv'):
with open(filename, 'w', newline='') as f:
fields = ['name', 'phone', 'category', 'rating', 'address', 'wa_link']
writer = csv.DictWriter(f, fieldnames=fields)
writer.writeheader()
for lead in leads:
lead['wa_link'] = generate_wa_link(lead)
writer.writerow({k: lead.get(k, '') for k in fields})
print(f'Exported {len(leads)} leads to {filename}')
# Pipeline: 4 categories = 4 queries = $0.02 total
leads = batch_maps_search(['restaurant', 'dentist', 'gym', 'salon'], 'Miami FL')
valid = extract_leads_with_phones(leads)
export_pipeline(valid)Python 示例
Python
import os, requests, re
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}
def maps_to_whatsapp(category, city):
data = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
json={'platform': 'google', 'query': f'{category} in {city}', 'type': 'maps'}).json()
for b in data.get('local_results', []):
phone = re.sub(r'\D', '', b.get('phone', ''))
if len(phone) >= 10:
print(f"{b['title']}: https://wa.me/{phone}")
maps_to_whatsapp('salon', 'Austin TX')JavaScript 示例
JavaScript
const res = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST',
headers: {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'},
body: JSON.stringify({platform: 'google', query: `${category} in ${city}`, type: 'maps'})
}).then(r => r.json());
res.local_results?.filter(b => b.phone).forEach(b => {
const phone = b.phone.replace(/\D/g, '');
console.log(`${b.title}: https://wa.me/${phone}`);
});预期输出
JSON
CSV with business name, phone, category, rating, address, and WhatsApp click-to-chat link. Category-specific message templates. 4 categories = $0.02 total.