nodejs使用fetch抓取geojson

时间:2020-05-10 14:02:25   收藏:0   阅读:135

地图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
            if (childCode == code) {
                continue
            } 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)

 

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!