码迷,mamicode.com
首页 > Web开发 > 详细

nodejs使用fetch抓取geojson

时间:2020-05-10 12:38:33      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:turn   text   i++   res   get   got   awl   length   pre   

地图geojson

http://datav.aliyun.com/tools/atlas/#&lat=33.90689555128866&lng=113.5052490234375&zoom=7

 

抓取代码

const fetch = require(‘node-fetch‘);
var fs = require("fs")

async function scrawl(code) {
    console.log(code + "gotten")
    if (code % 100 == 0) {
        let target = code + "_full";
        let result = await fetch(`https://geo.datav.aliyun.com/areas_v2/bound/${target}.json`)
        let text = await result.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
            await scrawl(childCode)
        }
        return;
    }
    let result = await fetch(`https://geo.datav.aliyun.com/areas_v2/bound/${code}.json`)
    let text = await result.text()
    fs.writeFileSync("data/" + code + ".json", text)
}

scrawl(100000)

 

nodejs使用fetch抓取geojson

标签:turn   text   i++   res   get   got   awl   length   pre   

原文地址:https://www.cnblogs.com/windyWu/p/12862717.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!