首页 > 编程语言 > 详细

python 利用淘宝IP库 查询IP归属地

时间:2018-05-04 13:42:44      阅读:158      评论:0      收藏:0      [点我收藏+]
#coding:utf-8
from django.test import TestCase

import json
import urllib

ip = "114.114.114.114"
url = "http://ip.taobao.com/service/getIpInfo.php?ip="+ ip

#返回数据
jsondata = json.loads(urllib.urlopen(url).read())
print jsondata

#省份
region = jsondata["data"]["region"]
#城市
city = jsondata["data"]["city"]
#运营商
isp = jsondata["data"]["isp"]
#国家
country = jsondata["data"]["country"]

print region
print city
print isp
print country

 结果:

{u‘code‘: 0, u‘data‘: {u‘city‘: u‘\u5357\u4eac‘, u‘area_id‘: u‘‘, u‘county_id‘: u‘xx‘, u‘region_id‘: u‘320000‘, u‘area‘: u‘‘, u‘city_id‘: u‘320100‘, u‘ip‘: u‘114.114.114.114‘, u‘region‘: u‘\u6c5f\u82cf‘, u‘isp‘: u‘XX‘, u‘country_id‘: u‘CN‘, u‘county‘: u‘XX‘, u‘isp_id‘: u‘xx‘, u‘country‘: u‘\u4e2d\u56fd‘}}
江苏
南京
XX
中国

 

python 利用淘宝IP库 查询IP归属地

原文:https://www.cnblogs.com/fanhua999/p/8989834.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!