高德地图电话号采集工具,百度腾讯高德地图手机号采集提取工具,python版

简介: 该工具支持高德/百度/腾讯三平台商家电话采集,包含多线程处理和数据去重功能‌37。使用时

下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:9182

该工具支持高德/百度/腾讯三平台商家电话采集,包含多线程处理和数据去重功能‌37。使用时需先申请各平台API密钥并配置到config.json中‌

import requests
import pandas as pd
from tqdm import tqdm
import json
import os
import time
from concurrent.futures import ThreadPoolExecutor

class MapPhoneScraper:
def init(self):
self.config = self._load_config()
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
}

def _load_config(self):
    """加载API密钥配置"""
    try:
        with open('config.json') as f:
            return json.load(f)
    except:
        return {
            "amap_key": "your_amap_key",
            "baidu_key": "your_baidu_key",
            "qq_key": "your_qq_key",
            "max_workers": 5,
            "output_dir": "output_data"
        }

def scrape_amap(self, keyword, city, pages=10):
    """高德地图POI采集"""
    base_url = "https://restapi.amap.com/v3/place/text"
    results = []

    for page in tqdm(range(1, pages+1), desc=f"高德采集[{city}-{keyword}]"):
        params = {
            'key': self.config['amap_key'],
            'keywords': keyword,
            'city': city,
            'offset': 25,
            'page': page,
            'extensions': 'all',
            'output': 'json'
        }

        try:
            resp = requests.get(base_url, params=params, headers=self.headers, timeout=10)
            data = resp.json()
            if data['status'] == '1':
                for poi in data['pois']:
                    results.append({
                        '来源': '高德地图',
                        '名称': poi.get('name'),
                        '地址': poi.get('address'),
                        '电话': poi.get('tel') or poi.get('detail_info', {}).get('tel'),
                        '经纬度': poi.get('location')
                    })
            time.sleep(0.5)
        except Exception as e:
            print(f"高德采集异常: {e}")

    return results

def scrape_baidu(self, keyword, region, pages=10):
    """百度地图POI采集"""
    base_url = "https://api.map.baidu.com/place/v2/search"
    results = []

    for page in tqdm(range(1, pages+1), desc=f"百度采集[{region}-{keyword}]"):
        params = {
            'query': keyword,
            'region': region,
            'output': 'json',
            'ak': self.config['baidu_key'],
            'scope': 2,
            'page_size': 20,
            'page_num': page-1
        }

        try:
            resp = requests.get(base_url, params=params, headers=self.headers, timeout=10)
            data = resp.json()
            if data.get('status') == 0:
                for poi in data.get('results', []):
                    results.append({
                        '来源': '百度地图',
                        '名称': poi.get('name'),
                        '地址': poi.get('address'),
                        '电话': poi.get('telephone') or poi.get('detail_info', {}).get('telephone'),
                        '经纬度': poi.get('location')
                    })
            time.sleep(0.5)
        except Exception as e:
            print(f"百度采集异常: {e}")

    return results

def scrape_qq(self, keyword, city, pages=10):
    """腾讯地图POI采集"""
    base_url = "https://apis.map.qq.com/ws/place/v1/search"
    results = []

    for page in tqdm(range(1, pages+1), desc=f"腾讯采集[{city}-{keyword}]"):
        params = {
            'keyword': keyword,
            'boundary': f'region({city},0)',
            'page_size': 20,
            'page_index': page,
            'key': self.config['qq_key']
        }

        try:
            resp = requests.get(base_url, params=params, headers=self.headers, timeout=10)
            data = resp.json()
            if data.get('status') == 0:
                for poi in data.get('data', []):
                    results.append({
                        '来源': '腾讯地图',
                        '名称': poi.get('title'),
                        '地址': poi.get('address'),
                        '电话': poi.get('tel'),
                        '经纬度': f"{poi.get('location', {}).get('lat')},{poi.get('location', {}).get('lng')}"
                    })
            time.sleep(0.5)
        except Exception as e:
            print(f"腾讯采集异常: {e}")

    return results

def batch_scrape(self, keywords, cities, platforms=['amap', 'baidu', 'qq']):
    """批量采集多平台数据"""
    all_data = []

    with ThreadPoolExecutor(max_workers=self.config.get('max_workers', 3)) as executor:
        futures = []
        for platform in platforms:
            for city in cities:
                for keyword in keywords:
                    if platform == 'amap':
                        futures.append(executor.submit(self.scrape_amap, keyword, city))
                    elif platform == 'baidu':
                        futures.append(executor.submit(self.scrape_baidu, keyword, city))
                    elif platform == 'qq':
                        futures.append(executor.submit(self.scrape_qq, keyword, city))

        for future in futures:
            all_data.extend(future.result())

    return all_data

def save_to_excel(self, data, filename=None):
    """保存数据到Excel"""
    if not os.path.exists(self.config['output_dir']):
        os.makedirs(self.config['output_dir'])

    df = pd.DataFrame(data)
    df = df.drop_duplicates(subset=['电话'], keep='first')

    if not filename:
        filename = f"商家电话_{time.strftime('%Y%m%d_%H%M%S')}.xlsx"

    save_path = os.path.join(self.config['output_dir'], filename)
    df.to_excel(save_path, index=False)
    print(f"数据已保存到: {save_path}")
    return save_path

if name == 'main':
scraper = MapPhoneScraper()

# 配置采集参数
keywords = ['餐饮', '酒店', '超市']  # 搜索关键词
cities = ['北京', '上海', '广州']    # 目标城市

# 执行采集
data = scraper.batch_scrape(keywords, cities)

# 保存结果
scraper.save_to_excel(data)
相关文章
|
7月前
|
存储 缓存 测试技术
理解Python装饰器:简化代码的强大工具
理解Python装饰器:简化代码的强大工具
|
8月前
|
程序员 测试技术 开发者
Python装饰器:简化代码的强大工具
Python装饰器:简化代码的强大工具
292 92
|
9月前
|
数据安全/隐私保护 Python
微信群成员导出工具, 微信群成员导出软件, 微信群管理工具软件【python】
这个工具提供了完整的微信群成员导出功能,包括登录微信、获取群列表、导出成员信息到Excel等功能
|
7月前
|
机器学习/深度学习 编解码 Python
Python图片上采样工具 - RealESRGANer
Real-ESRGAN基于深度学习实现图像超分辨率放大,有效改善传统PIL缩放的模糊问题。支持多种模型版本,推荐使用魔搭社区提供的预训练模型,适用于将小图高质量放大至大图,放大倍率越低效果越佳。
569 3
|
8月前
|
人工智能 自然语言处理 安全
Python构建MCP服务器:从工具封装到AI集成的全流程实践
MCP协议为AI提供标准化工具调用接口,助力模型高效操作现实世界。
1452 1
|
7月前
|
算法 安全 数据安全/隐私保护
Python随机数函数全解析:5个核心工具的实战指南
Python的random模块不仅包含基础的随机数生成函数,还提供了如randint()、choice()、shuffle()和sample()等实用工具,适用于游戏开发、密码学、统计模拟等多个领域。本文深入解析这些函数的用法、底层原理及最佳实践,帮助开发者高效利用随机数,提升代码质量与安全性。
1168 0
|
8月前
|
API 数据安全/隐私保护 Python
拼多多批量上架软件, 电商一键上货发布工具,python电商框架分享
多线程批量上传架构,支持并发处理商品数据 完整的拼多多API签名和token管理机制
|
8月前
|
安全 API 数据安全/隐私保护
|
8月前
|
Java API 数据安全/隐私保护
淘宝一键上货发布软件,淘宝批量发布上架工具, 淘宝批量上架脚本【python】
这个Python脚本实现了以下功能: 完整的淘宝API调用封装
|
8月前
|
机器人 数据安全/隐私保护 Python
淘宝批量发货发布工具, 淘宝批量上传商品软件, 淘宝批量上架软件【python】
使用Selenium实现自动化操作淘宝卖家后台 支持三种核心功能