标签:研究 淘宝 ice style 含义 使用 大致 http info
晚上看新闻时无意看到了淘宝IP查询API的信息,然后就顺手写了一个IP地址查询的脚本来分享
先贴出淘宝IP查询API的使用方法,以供读者研究:
1. 请求接口(GET): /service/getIpInfo.php?ip=[ip地址字串] 2. 响应信息: (json格式的)国家 、省(自治区或直辖市)、市(县)、运营商 3. 返回数据格式: {"code":0,"data":{"ip":"210.75.225.254","country":"\u4e2d\u56fd","area":"\u534e\u5317", "region":"\u5317\u4eac\u5e02","city":"\u5317\u4eac\u5e02","county":"","isp":"\u7535\u4fe1", "country_id":"86","area_id":"100000","region_id":"110000","city_id":"110000", "county_id":"-1","isp_id":"100017"}} 其中code的值的含义为,0:成功,1:失败。
这里返回的数据是json形式的,目前公开的API中返回的数据大致分为XML与json两种格式
贴出脚本源码:
ip.py
#!/usr/local/bin/python #coding = utf-8 #Author:Walter import urllib import urllib2 import json ip = raw_input(‘Please Enter IP Address:‘) url = "http://ip.taobao.com/service/getIpInfo.php?ip="+ip try: req = urllib2.Request(url) res_data = urllib2.urlopen(req) res = res_data.read() jsondata = json.loads(res) print "" print "IP Address:"+jsondata[‘data‘][‘ip‘] print "Country:"+jsondata[‘data‘][‘country‘] print "Area:"+jsondata[‘data‘][‘area‘] print "Region:"+jsondata[‘data‘][‘region‘] print "City:"+jsondata[‘data‘][‘city‘] print "ISP:"+jsondata[‘data‘][‘isp‘] except Exception as error: print error print "Sorry,We Got a Error.Please Try Again Or Check Your Internet."
标签:研究 淘宝 ice style 含义 使用 大致 http info
原文地址:http://www.cnblogs.com/superye/p/7442266.html