python3根据地址批量获取百度地图经纬度

时间:2022-10-14 21:46:11

python3代码如下:

import requests
import time
def get_mercator(addr):
url= 'http://api.map.baidu.com/geocoder/v2/?address=%s&output=json&ak=************************&callback=showLocation'%(addr)
response = requests.get(url)
return response.text
def TXTRead_Writeline(src,dest):
ms = open(src,encoding='utf-8')
for line in ms.readlines():
with open(dest,"a",encoding='utf-8') as mon:
loc=get_mercator(line)
mon.write(loc)
mon.write("\n")
time.sleep(1)
TXTRead_Writeline("D:\Data\\test.txt","D:\Data\\result.txt")