|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# LAOLIU
import os
import openpyxl
import requests as req
key="EUCBZ-MFEKV-QXRPL-U7G37-QEZ33-7NBYV"
def get_cor(address):
ret =req.get(
url = "https://apis.map.qq.com/ws/geocoder/v1/",
params={
'region' : ' 西安市',
'address':address,
"key": key
}
).json()
if ret.get('sutatus') == 0:
return ret.get('result').get('location')
else:
return None
if __name__=="main":
file_path = os.path.join(os.getcwd(), "test2.xlsx")
wb = openpyxl.load_workbook(file_path)
ws = wb['Sheet1']
for cell in ws['A']:
if cell.row > 1:
addr = cell.value
cor = get_cor(addr)
if cor:
ws[f'B{cell.row}'] = format(cor.get('lng'))
ws[f'c{cell.row}'] = format(cor.get('lat'))
wb.save(file_path)
print("任务完成")
这是一个根据地址搜索经纬度的程序,单次搜索已经成功了。批量处理的时候程序运行成功但没有结果。
|
|