高德地图 Js Api总结

0x00 API分类文档

https://lbs.amap.com/api/webservice/guide/api/search https://lbs.amap.com/api/webservice/guide/api/search#polygon https://lbs.amap.com/api/webservice/guide/api/convert/

0x01 分类示例

0x02 常用python解析文件库

  • json文件

  • csv文件

  • xml文件

0x03 部分代码

上海市POI

兴趣:地名、坐标、地址、类型、所在区、

'''
简单高德爬虫示例
'''
class POIController(object):
    def __init__(self,key):
        self.key = key
        self.keyword = ''
        self.city = ''
        self.offset = ''
        self.page = ''
        self.extension = 'all'
        self.url = ''
        self.json = ''
        self.file = ''
        print('-------初始化成功-------')
    '''
    设置属性:爬取参数
    '''
    def setproperties(self,city,keyword,offset,page,extension='all'):
        self.keyword = keyword
        self.city = city
        self.offset = offset
        self.page = page
        self.extension = extension
        self.url = 'http://restapi.amap.com/v3/place/text?&keywords='+self.keyword+'&city='+self.city+'&output=json&offset='+str(self.offset)+'&page='+str(self.page)+'&key='+self.key+'&extensions='+self.extension
    '''
    返回文本
    '''
    def url2text(self):
        req = requests.get(self.url)
        text = json.loads(req.text)
        return text

    '''
    返回json
    '''
    def text2json(self,text):
        self.poi = self.url2text().get('pois')
        print('poi字典大小:%d'%len(self.poi))
        return self.poi

    '''
    把POI的数据进行整理
    '''
    def json2plain(self,p):
        name = p.get('name')
        type = p.get('type')
        address = p.get('address')
        location = p.get('location')
        result = name + ',' + type + ',' + location + ',' + address + '\n'
        return result

    def poi2txt(self,fname='test.txt'):
        f = open(fname,'w+')
        for p in self.poi:
            f.write(self.json2plain(p))
        f.close()

    def poi2txt(self,mpage):
        self.url = 'http://restapi.amap.com/v3/place/text?&keywords='+self.keyword+'&city='+self.city+'&output=json&offset='+str(self.offset)+'&page='+str(mpage)+'&key='+self.key+'&extensions='+self.extension
        text = self.url2text()
        poi = self.text2json(text)
        for p in poi:
            self.file.write(self.json2plain(p))

    def poi2txtplus(self,pages,fname='poires.txt'):
        self.file = open(fname,'a+')

        if(len(pages)<0):
            print('传入错误')
        for p in pages:
            self.poi2txt(p)

    def poi2file(self, mpage,poitype):
        self.url = 'http://restapi.amap.com/v3/place/text?&keywords=' + poitype + '&city=' + self.city + '&output=json&offset=' + str(
            self.offset) + '&page=' + str(mpage) + '&key=' + self.key + '&extensions=' + self.extension
        text = self.url2text()
        poi = self.text2json(text)
        for p in poi:
            self.file.write(self.json2plain(p))

    def poi2txtplus(self, pages, poitype,fname):
        self.file = open(fname, 'a+')
        if (len(pages) < 0):
            print('传入参数错误')
        for type in poitype:
            for p in pages: 
                print('爬取内容:%s %s 页码-%d' % (city, type, p))
                self.poi2file(p,str(type))

0x04 别人的文章

CoolCats
CoolCats
理学学士

我的研究兴趣是时空数据分析、知识图谱、自然语言处理与服务端开发