依赖
1 2 3 4 5 6 7 8
| { "dependencies": { "axios": "^1.4.0", "colors": "^1.4.0", "express": "^4.18.2", "fs": "^0.0.1-security" } }
|
数据来源
1
| https://datav.aliyun.com/portal/school/atlas/area_selector
|
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| const axios = require('axios'); const fs = require("fs"); const colors = require('colors');
function getData(code="100000_full"){ axios.get("https://geo.datav.aliyun.com/areas_v3/bound/"+code+".json").then(res=>{ console.log('=========== 数据读取成功 ==========='.yellow); console.log(res.data); console.log('========== ============= =========='.yellow);
const writerStream = fs.createWriteStream("data/"+parseInt(code)+'.json'); writerStream.write(JSON.stringify(res.data)); writerStream.end();
writerStream.on('finish', function () { console.log('<<<------------------------------- 写入完成 ------------------------------->>>\n'.green); }); writerStream.on('error', function (err) { console.log('<<<------------------------------- 写入错误 ------------------------------->>>\n'.red); });
if(res.data.features.length>1){ res.data.features.map(item => { if(item.properties.childrenNum){ getData(item.properties.adcode+"_full") }else{ getData(item.properties.adcode) } }) } }).catch(err=>{ console.log('========== 数据读取错误 =========='.red); }) }; getData();
|
结果
https://gitee.com/gitee-cherry/get-geoData