需要把mykey替换为自己再高德中申请的key
# -*- coding: utf-8 -*-
import openpyxl as op
import urllib.request # 发送请求
from urllib import parse # URL编码
import json # 解析json数据
from math import ceil
from openpyxl import load_workbook # 从Excel中读取镇街名称
# 关键字搜索API服务地址:https://restapi.amap.com/v3/place/text?parameters/ 请求方式 GET
# parameters代表的参数包括必填参数和可选参数。所有参数均使用和号字符(&)进行分隔。
mykey = "替换为自己的key"
city = "四川"
keywords = "物资库"
types = ""
dict_location = {}
def get_page():
parameters = "key={}&keywords={}&types={}&city={}&children=0&offset=&page=1&extensions=all" \
.format(mykey, keywords, types, city) # 参数
url = "https://restapi.amap.com/v3/place/text?{}".format(parameters) # 拼接请求
newUrl = parse.quote(url, safe="/:=&?#+!$,;'@()*[]") # 编码
response = urllib.request.urlopen(newUrl) # 发送请求
data = response.read() # 接收数据
jsonData = json.loads(data) # 解析json文件
page = eval(jsonData['count'])
return page
def get_json(page):
parameters = "key={}&keywords={}&types={}&city={}&children