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=地铁站®ion=苏州市&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文件中的数据如图所示