2019独角兽企业重金招聘Python工程师标准>>>
手机号码归属地查询API,最多只能查到省份。
示例代码:
#-*- coding: utf-8 -*-
#version:0.1
#note:该即用API能查询电话号码基本归属信息(只能查到省份)import urllib.request
import json
import collectionsurl = "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'])
运行结果: