美文网首页
使用淘宝ip库解析ip地址

使用淘宝ip库解析ip地址

作者: HouserLin | 来源:发表于2016-10-22 09:33 被阅读468次

API地址:[http://ip.taobao.com/instructions.php]

# -*- coding:utf-8 -*-
import requests

def ip_parsing(ip):
    payload = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'}
    link = 'http://ip.taobao.com/service/getIpInfo.php?ip=' + ip
    r = requests.get(link,params = payload)
    country = r.json()['data']['country']
    area = r.json()['data']['area']
    region = r.json()['data']['region']
    city = r.json()['data']['city']
    isp = r.json()['data']['isp']
    return country,area,region,city,isp
country,area,region,city,isp = ip_parsing('58.61.233.124')
print '\t'.join([country,area,region,city,isp])

相关文章

网友评论

      本文标题:使用淘宝ip库解析ip地址

      本文链接:https://www.haomeiwen.com/subject/rhzcuttx.html