百度ip定位城市接口调用

http://lbsyun.baidu.com/index.php?title=webapi/ip-api

 

require 'rubygems'
require 'json'
print ARGV 
print "fist is :",ARGV[0]
logfile="#{ARGV[0]}_log"

filex = File.open(logfile, "w+")


File.foreach(ARGV[0]) do |line|  
    line = line.gsub("\n", "")
    result = `curl "http://api.map.baidu.com/location/ip?ak=xxxx&ip=#{line}"`  
    puts  "http://api.map.baidu.com/location/ip?ak=xxxx&ip=#{line}" 
    puts result   
  begin
        filex << "#{line}:#{JSON.parse(result)["content"]["address_detail"]["province"] }  #{JSON.parse(result)["content"]["address_detail"]["city"] }"
    rescue
        filex << "#{line}: #{''}"
    end
    filex << "\n"
break 
end

将ak替换成自己的ak, 参数为全是ip 每行一个的文件;

普通开发者每天2000次调用,升级个人开发者可达到3w ;

 个人认证:http://lbsyun.baidu.com/apiconsole/auth#/creat/person

 

posted on 2019-04-22 15:44  iokde.com  阅读(885)  评论(0编辑  收藏  举报

导航