nodejs使用fetch抓取geojson
地图geojson
http://datav.aliyun.com/tools/atlas/#&lat=33.90689555128866&lng=113.5052490234375&zoom=7
抓取代码
async function scrawl(code) {
console.log(code + "gotten")
if (code % 100 == 0) {
let target = code + "_full";
let text = await fetch(`https://geo.datav.aliyun.com/areas_v2/bound/${target}.json`).then(res=>res.text())
fs.writeFileSync("data/" + target + ".json", text)
let json = JSON.parse(text)
let features = json.features;
for (let i = 0; i < features.length; i++) {
let childCode = features[i].properties.adcode
if (childCode == code) {
continue
}
await scrawl(childCode)
}
return;
}
let text = await fetch(`https://geo.datav.aliyun.com/areas_v2/bound/${code}.json`).then(res=>res.text())
fs.writeFileSync("data/" + code + ".json", text)
}
scrawl(100000)