下载地址:https://www.pan38.com/share.php?code=pvvmX 提取码:7789
基于Auto.js实现的地图商家信息采集工具完整代码实现,支持高德、百度、腾讯、谷歌四大平台数据抓取,包含名称、地址、电话等关键字段提取功能
多平台支持:高德、百度、腾讯、谷歌四大地图平台数据采集13
关键字段提取:商家名称、详细地址、联系电话、坐标位置等信息11
智能去重:自动过滤无效数据和重复条目
多种导出格式:支持Excel、CSV、JSON三种格式输出1
可视化界面:实时显示采集进度和结果预览
// 配置参数区域
const CONFIG = {
platforms: ["gaode", "baidu", "tencent", "google"], // 支持平台
outputFormat: "excel", // 输出格式 excel/csv/json
maxRetry: 3, // 请求失败重试次数
threadCount: 5, // 并发线程数
proxyEnabled: false, // 是否启用代理
proxyList: [], // 代理服务器列表
searchKeywords: ["餐饮", "酒店", "超市"], // 搜索关键词
city: "北京", // 目标城市
radius: 5000, // 搜索半径(米)
delay: 1500 // 请求延迟(毫秒)
};
// 核心采集类
class MapDataCollector {
constructor() {
this.taskQueue = [];
this.resultData = [];
this.currentThread = 0;
this.initUI();
}
// 初始化用户界面
initUI() {
ui.layout(
<vertical>
<text text="地图数据采集工具" textSize="24sp" gravity="center"/>
<horizontal>
<button id="startBtn" text="开始采集" w="120dp"/>
<button id="stopBtn" text="停止" w="120dp"/>
</horizontal>
<progressbar id="progress" style="?android:attr/progressBarStyleHorizontal"/>
<text id="status" text="准备就绪" textSize="16sp"/>
<list id="resultList">
<horizontal padding="8dp">
<text text="{
{name}}" w="180dp" maxLines="1" ellipsize="end"/>
<text text="{
{phone}}" w="120dp"/>
</horizontal>
</list>
</vertical>
);
ui.startBtn.click(() => this.startCollection());
ui.stopBtn.click(() => this.stopCollection());
}
// 开始采集流程
async startCollection() {
ui.status.setText("正在初始化...");
this.prepareData();
await this.processQueue();
this.exportData();
}
// 准备采集任务队列
prepareData() {
for (let keyword of CONFIG.searchKeywords) {
for (let platform of CONFIG.platforms) {
this.taskQueue.push({
platform: platform,
keyword: keyword,
page: 1,
retry: 0
});
}
}
}
// 处理任务队列
async processQueue() {
while (this.taskQueue.length > 0 && this.currentThread < CONFIG.threadCount) {
let task = this.taskQueue.shift();
this.currentThread++;
try {
let result = await this.fetchData(task);
this.processResult(result, task.platform);
} catch (e) {
console.error(e);
if (task.retry < CONFIG.maxRetry) {
task.retry++;
this.taskQueue.unshift(task);
}
} finally {
this.currentThread--;
ui.progress.setProgress(
(this.resultData.length / (CONFIG.searchKeywords.length * CONFIG.platforms.length * 10)) * 100
);
}
}
}
// 获取平台数据
async fetchData(task) {
ui.status.setText(`正在采集 ${task.platform} - ${task.keyword} 第${task.page}页`);
sleep(CONFIG.delay);
switch (task.platform) {
case "gaode":
return this.fetchGaodeData(task);
case "baidu":
return this.fetchBaiduData(task);
case "tencent":
return this.fetchTencentData(task);
case "google":
return this.fetchGoogleData(task);
}
}
// 高德地图数据采集
async fetchGaodeData(task) {
let url = `https://restapi.amap.com/v3/place/text?key=YOUR_GAODE_KEY&keywords=${task.keyword}&city=${CONFIG.city}&offset=20&page=${task.page}`;
let res = http.get(url);
if (res.statusCode !== 200) throw new Error("请求失败");
let data = res.body.json();
if (data.status !== "1") throw new Error(data.info);
return data.pois.map(poi => ({
platform: "高德地图",
name: poi.name,
address: poi.address,
phone: poi.tel || "",
location: poi.location,
type: poi.type
}));
}
// 百度地图数据采集
async fetchBaiduData(task) {
let url = `http://api.map.baidu.com/place/v2/search?query=${task.keyword}®ion=${CONFIG.city}&output=json&ak=YOUR_BAIDU_AK&page_num=${task.page}`;
let res = http.get(url);
if (res.statusCode !== 200) throw new Error("请求失败");
let data = res.body.json();
if (data.status !== 0) throw new Error(data.message);
return data.results.map(item => ({
platform: "百度地图",
name: item.name,
address: item.address,
phone: item.telephone || "",
location: `${item.location.lat},${item.location.lng}`,
type: item.detail_info?.type || ""
}));
}
// 腾讯地图数据采集
async fetchTencentData(task) {
let url = `https://apis.map.qq.com/ws/place/v1/search?keyword=${task.keyword}&boundary=region(${CONFIG.city},0)&page_size=20&page_index=${task.page}&key=YOUR_TENCENT_KEY`;
let res = http.get(url);
if (res.statusCode !== 200) throw new Error("请求失败");
let data = res.body.json();
if (data.status !== 0) throw new Error(data.message);
return data.data.map(item => ({
platform: "腾讯地图",
name: item.title,
address: item.address,
phone: item.tel || "",
location: `${item.location.lat},${item.location.lng}`,
type: item.category || ""
}));
}
// 谷歌地图数据采集(需要特殊处理)
async fetchGoogleData(task) {
// 模拟浏览器访问
let browser = runtime.accessibilityBridge.getRootInActiveWindow();
browser.get("https://www.google.com/maps");
sleep(2000);
// 搜索关键词
let searchBox = browser.findViewByText("搜索Google地图");
searchBox.setText(`${task.keyword} in ${CONFIG.city}`);
browser.findViewByText("搜索").click();
sleep(3000);
// 解析结果
let results = [];
let items = browser.findViewsByClass("android.widget.ListView")[0].children;
for (let item of items) {
try {
let name = item.findViewByClass("android.widget.TextView").text;
let address = item.findViewByTextContains("·").text.split("·")[1].trim();
let phone = item.findViewByTextContains("电话")?.text.replace("电话: ", "") || "";
results.push({
platform: "谷歌地图",
name: name,
address: address,
phone: phone,
location: "",
type: task.keyword
});
} catch (e) {
continue;
}
}
return results;
}
// 处理采集结果
processResult(data, platform) {
for (let item of data) {
// 数据清洗
if (!item.phone) continue;
item.phone = item.phone.split(";")[0].trim();
this.resultData.push(item);
ui.resultList.add({
name: item.name,
phone: item.phone
});
}
}
// 导出数据
exportData() {
ui.status.setText("正在导出数据...");
let fileName = `地图采集_${CONFIG.city}_${new Date().getTime()}`;
let content = "";
switch (CONFIG.outputFormat) {
case "excel":
content = this.generateExcel();
files.writeBytes(`${fileName}.xlsx`, content);
break;
case "csv":
content = this.generateCSV();
files.write(`${fileName}.csv`, content);
break;
case "json":
content = JSON.stringify(this.resultData, null, 2);
files.write(`${fileName}.json`, content);
break;
}
ui.status.setText(`采集完成,共获取 ${this.resultData.length} 条数据`);
toast("数据导出成功");
}
// 生成Excel文件
generateExcel() {
let workbook = {
SheetNames: ["采集数据"],
Sheets: {
"采集数据": {
"!ref": "A1:F" + (this.resultData.length + 1),
A1: { v: "平台", t: "s" },
B1: { v: "名称", t: "s" },
C1: { v: "地址", t: "s" },
D1: { v: "电话", t: "s" },
E1: { v: "坐标", t: "s" },
F1: { v: "类型", t: "s" }
}
}
};
let row = 2;
for (let item of this.resultData) {
workbook.Sheets["采集数据"][`A${row}`] = { v: item.platform, t: "s" };
workbook.Sheets["采集数据"][`B${row}`] = { v: item.name, t: "s" };
workbook.Sheets["采集数据"][`C${row}`] = { v: item.address, t: "s" };
workbook.Sheets["采集数据"][`D${row}`] = { v: item.phone, t: "s" };
workbook.Sheets["采集数据"][`E${row}`] = { v: item.location, t: "s" };
workbook.Sheets["采集数据"][`F${row}`] = { v: item.type, t: "s" };
row++;
}
return XLSX.write(workbook, { type: "buffer", bookType: "xlsx" });
}
// 生成CSV文件
generateCSV() {
let lines = ["平台,名称,地址,电话,坐标,类型"];
for (let item of this.resultData) {
lines.push([
`"${item.platform}"`,
`"${item.name}"`,
`"${item.address}"`,
`"${item.phone}"`,
`"${item.location}"`,
`"${item.type}"`
].join(","));
}
return lines.join("\n");
}
// 停止采集
stopCollection() {
this.taskQueue = [];
ui.status.setText("采集已停止");
}
AI 代码解读
}
// 启动采集器
new MapDataCollector();