仅列出标题 列出摘要

python通过ip获取地址

# -*- coding: utf-8 -*-

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

#查找IP地址

defip_location(ip):

    data = urllib.urlopen(url + ip).read()

    datadict=json.loads(data)

    for oneinfo in datadict:

        if "code" == oneinfo:

            if datadict[oneinfo] == 0:

                return datadict["data"]["country"] + datadict["data"]["region"] + datadict["data"]["city"] + datadict["data"]["isp"]

posted on 2014-04-12 15:16  baoyiluo  阅读(407)  评论(0编辑  收藏  举报