1. 获取Web服务API
2. 准备url
# -- coding:utf-8 --
import json
import requests
ak = '申请的访问应用(AK)'
params = {
'query': '地铁站',
'tag': '交通设施',
'region': '武汉',
'output': 'json',
'scope': '1',
'ak': ak,
'page_size': 10,
'page_num': 0
}
url = 'https://api.map.baidu.com/place/v2/search?'
3. 返回数据
data = []
flag = 1
while flag:
rsp = requests.get(url, params=params)
if rsp.json()['results']:
params['page_num'] += 1
for i in rsp.json()['results']:
data.append(i)
else:
flag = 0
print(len(data))
# print(rsp.url)
with open('poi.json', 'w', encoding='utf-8') as f:
json.dump(data, f, indent=4, ensure_ascii=False)
标签:url,地铁站,ak,爬虫,data,json,params,POI,rsp
From: https://www.cnblogs.com/khrushchefox/p/16916709.html