突然发现百度的API越来越好用了,简单使用百度API精准定位IP地址。附Python代码
2016-11-27 16:38
686 查看
2016年11月27日08:13:13
API服务地址:
http://lbsyun.baidu.com/index.php?title=webapi/high-acc-ip
使用方法:
第一步,申请密钥(AK) ,作为访问服务的依据;
第二步,拼写发送HTTP/HTTPS请求的URL,注意需使用第一步申请的AK;
第三步,接收HTTP/HTTPS请求返回的数据(JSON/JSONP格式)
服务地址:
http://api.map.baidu.com/highacciploc/v1
https://api.map.baidu.com/highacciploc/v1
注意:申请开发者认证的时候,使用163邮箱认证失败,不知道是为什么(2016年11月27日08:23:32)
测试地址:
http://api.map.baidu.com/highacciploc/v1?qcip=139.214.254.47&qterm=pc&ak=naW5VG6u5TELUZ2stDslQPsYirKoIOFz&coord=bd09ll&extensions=3
反馈结果:
{"content":{"location":{"lat":43.862307,"lng":125.332422},"locid":"fb823867162b178b3e180993e4638d41","radius":2060684,"confidence":0.2,"address_component":{"country":"中国","province":"吉林省","city":"长春市","district":"南关区","street":"人民大街","street_number":"5766号","admin_area_code":220102},"formatted_address":"吉林省长春市南关区人民大街5766号","business":"人民大街,南岭,南湖公园"},"result":{"error":161,"loc_time":"2016-11-27
08:36:41"}}
=====================
输入结果
{"content":{"location":{"lat":43.862307,"lng":125.332422},"locid":"180d8c65fa25fefaf6eb9ae6481e1f4c","radius":2060684,"confidence":0.2,"address_component":{"country":"中国","province":"吉林省","city":"长春市","district":"南关区","street":"人民大街","street_number":"5766号","admin_area_code":220102},"formatted_address":"吉林省长春市南关区人民大街5766号","business":"人民大街,南岭,南湖公园"},"result":{"error":161,"loc_time":"2016-11-27
10:45:03"}}
位置:吉林省长春市南关区人民大街5766号
商圈:人民大街,南岭,南湖公园
经度:43.862307
维度:125.332422
准确度:0.2
API服务地址:
http://lbsyun.baidu.com/index.php?title=webapi/high-acc-ip
使用方法:
第一步,申请密钥(AK) ,作为访问服务的依据;
第二步,拼写发送HTTP/HTTPS请求的URL,注意需使用第一步申请的AK;
第三步,接收HTTP/HTTPS请求返回的数据(JSON/JSONP格式)
服务地址:
http://api.map.baidu.com/highacciploc/v1
https://api.map.baidu.com/highacciploc/v1
注意:申请开发者认证的时候,使用163邮箱认证失败,不知道是为什么(2016年11月27日08:23:32)
测试地址:
http://api.map.baidu.com/highacciploc/v1?qcip=139.214.254.47&qterm=pc&ak=naW5VG6u5TELUZ2stDslQPsYirKoIOFz&coord=bd09ll&extensions=3
反馈结果:
{"content":{"location":{"lat":43.862307,"lng":125.332422},"locid":"fb823867162b178b3e180993e4638d41","radius":2060684,"confidence":0.2,"address_component":{"country":"中国","province":"吉林省","city":"长春市","district":"南关区","street":"人民大街","street_number":"5766号","admin_area_code":220102},"formatted_address":"吉林省长春市南关区人民大街5766号","business":"人民大街,南岭,南湖公园"},"result":{"error":161,"loc_time":"2016-11-27
08:36:41"}}
# -*- coding: utf-8 -*- import requests import json s = requests.session() url = 'http://api.map.baidu.com/highacciploc/v1?qcip=139.214.254.47&qterm=pc&ak=YourKey&coord=bd09ll&extensions=3' header = {'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0'} response = s.get(url, headers = header, timeout = 20) print(response.text) json = json.loads(response.text) print('位置:'+str(json['content']['formatted_address'])) print('商圈:'+str(json['content']['business'])) print('经度:'+str(json['content']['location']['lat'])) print('维度:'+str(json['content']['location']['lng'])) print('准确度:'+str(json['content']['confidence'])) #练习时间:2016年11月27日10:54:36 #1、注意使用字符编码。 #2、注意修改requests请求header中的User-Agent。 #3、json返回的数据可能是int或者float等,打印时注意字符转换。 #4、替换API中你需要查询的IP地址和你的Key字符串。
=====================
输入结果
{"content":{"location":{"lat":43.862307,"lng":125.332422},"locid":"180d8c65fa25fefaf6eb9ae6481e1f4c","radius":2060684,"confidence":0.2,"address_component":{"country":"中国","province":"吉林省","city":"长春市","district":"南关区","street":"人民大街","street_number":"5766号","admin_area_code":220102},"formatted_address":"吉林省长春市南关区人民大街5766号","business":"人民大街,南岭,南湖公园"},"result":{"error":161,"loc_time":"2016-11-27
10:45:03"}}
位置:吉林省长春市南关区人民大街5766号
商圈:人民大街,南岭,南湖公园
经度:43.862307
维度:125.332422
准确度:0.2
相关文章推荐
- Android上实现一个简单的天气预报APP(十四) 使用百度API定位城市
- Python使用百度API上传文件到百度网盘代码分享
- Python使用百度API上传文件到百度网盘代码分享
- 百度定位API使用方法
- Android 系统api实现定位及使用百度提供的api来实现定位
- 百度定位API使用方法
- 基于Python使用CloudSight API实现简单的图像识别(image Recognition)
- HTML5手机定位-使用百度API
- Python使用Socket(Https)Post登录百度的实现代码
- 【经验小谈】百度定位api使用 百度定位demo 百度地图快速定位 百度地图获取当前位置 获取自己的位置 百度定位示例
- 百度地图SDK---实现简单定位功能思路解析(采用BaiduMapsAPIDemo代码)
- 使用百度API实现热点(WIFI)、GPS、基站定位
- Android中使用百度API定位,并实现手势操作(显示最后点击地图的位置)
- Android百度定位API使用方法
- Android 百度定位API使用方法
- 一个简单的使用代理访问百度页面内容的python脚本
- Python使用Socket(Https)Post登录百度的实现代码
- Python使用Socket(Https)Post登录百度的实现代码
- 【代码】Android 使用百度定位SDK 方法及处理错误
- sigar模块之python api简单的使用--获取cpu信息