完整代码如下,需要先行申请开发者KEY,代码先放在这里,开发思路以后有时间再详细写。
需要使用的话,可以下载下面编译好的程序
https://download.csdn.net/download/ashtyukjhf/18860618
import requests
class getPOI():
def getPOIcore(self):
url=u"https://restapi.amap.com/v3/place/text?parameters"
r=requests.get(url, params=self.params)
data=eval(r.text)
self.count=int(data['count'])
for poi in data['pois']:
try:
print(poi['id'],poi['name'],poi['adname'],poi['business_area'],poi['address'],poi['location'],poi['type'],sep=',',file=self.outfile)
except :pass
def __init__(self,region:str,keywords='',types=''):
if keywords==types=='':
print("类型和关键字不能同时为空")
self.params={
'key': '######请到高德开放平台申请#####',
'keywords': keywords,
'types':types,
'region':region,
'page':1,
'city_limit':'true',
'extensions':'all'
}
filename=region+keywords+types+'POI数据.csv'
headers=['id','名称','区县','商圈','地址','经度,纬度','类型']
with open(filename, mode='w+', encoding='utf-8') as self.outfile:
print(*headers, sep=',',file=self.outfile)
i=0
while True:
i+=1;
self.params['page']=i
self.getPOIcore()
if i==1:
print(region,keywords,types,'总计数据',self.count,'条')
if i>int(self.count/20):
break
pass
print('使用说明:\n输入区域、关键字或类型,即可获取相应POI数据\n其中类型和关键字可有一项为空\n例如:\n区域:岳麓区\n关键字:\n类型:餐饮\n\n\n')
region=input('请指定区域:')
keywords=input('指定关键字:')
types=input('指定类型:')
getPOI(region=region,keywords=keywords,types=types)
input('数据获取完毕')