zoukankan      html  css  js  c++  java
  • API精准定位IP地址

    突然发现百度的API越来越好用了,简单使用百度API精准定位IP地址。附Python代码

     

    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"}}


    [python] view plain copy
     
    1. # -*- coding: utf-8 -*-  
    2. import requests  
    3. import json  
    4.   
    5. s = requests.session()  
    6. url = 'http://api.map.baidu.com/highacciploc/v1?qcip=139.214.254.47&qterm=pc&ak=YourKey&coord=bd09ll&extensions=3'  
    7. header = {'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0'}  
    8. response = s.get(url, headers = header, timeout = 20)  
    9. print(response.text)  
    10.   
    11. json = json.loads(response.text)  
    12.   
    13. print('位置:'+str(json['content']['formatted_address']))  
    14. print('商圈:'+str(json['content']['business']))  
    15. print('经度:'+str(json['content']['location']['lat']))  
    16. print('维度:'+str(json['content']['location']['lng']))  
    17. print('准确度:'+str(json['content']['confidence']))  
    18.   
    19. #练习时间:2016年11月27日10:54:36  
    20. #1、注意使用字符编码。  
    21. #2、注意修改requests请求header中的User-Agent。  
    22. #3、json返回的数据可能是int或者float等,打印时注意字符转换。  
    23. #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
    当值未一旬,而视茫茫,而发苍苍,而齿牙动摇
  • 相关阅读:
    vue-awesome-swiper-T 轮播图
    transition-T 手机端滑动验证
    VUE-T
    跨域配置-Access-Control-Allow-Origin
    HTML中CSS引入图片并铺满背景
    mysql_affected_rows()、mysql_fetch_row、mysql_fetch_assoc
    tp框架的四种路由方式
    sql注入
    禁用cookie,怎么获得session
    git解决冲突的方法
  • 原文地址:https://www.cnblogs.com/niuniuc/p/7244874.html
Copyright © 2011-2022 走看看