PYthon百度地图API获取地铁站经纬度

from urllib import request
from urllib.parse import quote
import json
import string
subwayList = []
with open('data', 'r') as f:
    subwayList=f.read().strip(',').split('\n')

def startGet():
    for emp in subwayList:
        print(emp)
        getLocation(address=emp)

def getLocation(address='address'):
    url = "http://api.map.baidu.com/place/v2/search?query="+address+"&tag=地铁站&region=苏州市&output=json&ak=自己申请的key"
    url = quote(url, safe=string.printable)
    req = request.urlopen(url)
    res = req.read().decode('utf-8','ignore').replace(u'\xa9', u'')
    result = json.loads(res)
    print(result)

if __name__ == '__main__':
    startGet()

在这里插入图片描述data文件中的数据如图所示

猜你喜欢

转载自blog.csdn.net/weixin_41884808/article/details/116641669