手机号码归属地查询API,最多只能查到省份。html
示例代码:python
#-*- coding: utf-8 -*- #version:0.1 #note:该即用API能查询电话号码基本归属信息(只能查到省份) import urllib.request import json import collections url = "http://apistore.baidu.com/microservice/mobilephone?tel=" tel = input("输入你想查询的电话号码:") url = url + tel #完整的URL result = 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'])