使用淘宝ip库解析ip地址

2016-10-22  本文已影响468人  HouserLin

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])

上一篇下一篇

猜你喜欢

热点阅读