import json,time
from urllib import request
import requests
# key ='xxxxxxxxxxxx'
#polygon='121.953679,30.181944|122.322236,29.940442'
# types=120304
# size=25
url_base='http://restapi.amap.com/v3/place/polygon?key=xxxxxxxxxxxxxxxx&polygon=121.956409,30.178268|122.328571,29.93579|122.03606,29.982192|122.291492,30.093944&types=080100|080101|080102|080103|80104|080105|080106|080107|080108|080110|080111|080112|080113|080114|080115|080116|080117|080118|080119|080200|080201|080202&page_size=25&page_num={0}'
num=1
out=[]
while num<=20:
url=url_base.format(num)
print(url)
html=request.urlopen(url).read()
t=json.loads(html)
# print(t)
p=t['pois']
# print(p)
f=['address', 'pname', 'cityname', 'type', 'typecode', 'adname', 'name', 'location']
for poi in p:
line=[]
for i in f:
line.append(poi[i])
line.append(poi['location'].split(',')[0])
line.append(poi['location'].split(',')[1])
out.append(line)
print(line)
print(num)
num+=1
timemark=str(time.strftime('%Y%m%d%H%M%s'))
output = open('poi_{0}.txt'.format(timemark),'wb')
title ='\t'.join(f)+'\tx\ty\n'
output.write(title.encode('utf8'))
# print(title.encode('utf8'))
for l in out :
output.write(('\t'.join(l)+'\n').encode('utf8'))
# print(('\t'.join(l)+'\n').encode('utf8'))
output.close()
python通过高德对外接口爬取小区信息
于 2023-12-31 20:15:14 首次发布