,最多只能查到省份。
示例代码:
#-*- coding: utf-8 -*-#version:0.1#note:该即用API能查询电话号码基本归属信息(只能查到省份)import urllib.requestimport jsonimport collectionsurl = "http://apistore.baidu.com/microservice/mobilephone?tel="tel = input("输入你想查询的电话号码:")url = url + tel #完整的URLresult = urllib.request.urlopen(url).read().decode("utf-8") info = json.loads(result,object_pairs_hook=collections.OrderedDict) #json格式转换为python格式,并指定为有序字典if (info['errNum'] == -1): #查找失败 print(info['errMsg'])else: #输出天气相关信息 print("你查询的IP地址信息如下:") print("电话号码:", info['retData']['telString']) print("省份:", info['retData']['province']) print("运营商:", info['retData']['carrier'])运行结果: