百度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("
", "")
    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 << "
"
break 
end

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

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

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

原文地址:https://www.cnblogs.com/lavin/p/10750545.html