python查询IP对应的地理位置
2016-05-09 16:48
661 查看
这次我们使用淘宝给出的接口进行调用。原本还想用在项目中做统计分析,但是感觉数据量大了之后会出现问题。
#coding = utf-8
import urllib2
import json
ip = "182.90.42.221"
apiurl = "http://ip.taobao.com/service/getIpInfo.php?ip=%s" % ip
content = urllib2.urlopen(apiurl).read()
data = json.loads(content)['data']
code = json.loads(content)['code']
if code == 0:
print "ip:%s from %s%s%s \n" % (data["ip"].encode('utf-8'),data["country"].encode('utf-8'),data["region"].encode('utf-8'),data["city"].encode('utf-8'))
else:
print data.encode('utf-8')
#coding = utf-8
import urllib2
import json
ip = "182.90.42.221"
apiurl = "http://ip.taobao.com/service/getIpInfo.php?ip=%s" % ip
content = urllib2.urlopen(apiurl).read()
data = json.loads(content)['data']
code = json.loads(content)['code']
if code == 0:
print "ip:%s from %s%s%s \n" % (data["ip"].encode('utf-8'),data["country"].encode('utf-8'),data["region"].encode('utf-8'),data["city"].encode('utf-8'))
else:
print data.encode('utf-8')
相关文章推荐
- Python 数据分析包:pandas 基础
- Python sort( ) sorted( ) reverse( ) reversed( ) 总结
- Python pip distribute
- python reverse()方法
- wxPython-多个按钮使用同一个回调函数
- python 装饰器 中的 *args 和 **kwargs
- 爬取分页的标题
- Python学习路程day14
- python 以十六进制输出字符串
- python sort()方法
- python内置模块string源码浅析之maketrans
- python爬虫问题:error: command 'gcc' failed with exit status 1
- Mac OS X下搭建Python3.5.1+PyQt5.6开发环境
- vagrant系列教程(五):vagrant搭建python开发环境
- Python自然语言处理
- Python编程入门
- Python 并发
- python 内置函数 reversed()
- python压缩解压
- python 3 比较字符串