获取指定IP地址对应的物理位置

# -*- coding: utf-8 -*-
import requests
 
def get_physical_location(ip):
    url = 'http://ip.taobao.com/service/getIpInfo.php?ip=' + ip
    r = requests.get(url)
    if r.json()['code']:
        print '您输入的ip地址有误,请检查后再试。'
    else:
        country = r.json()['data']['country']
        region = r.json()['data']['region']
        city = r.json()['data']['city']
        return country + region + city

如果您觉得我的文章对您有帮助并想鼓励我继续原创,请扫描下方二维码进行打赏!

谢谢!

原文地址:https://www.cnblogs.com/yestreenstars/p/5481802.html