# pip install phone
from phone import Phone
def getPhoneInfo(phoneNum):#查询函数
info = Phone().find(phoneNum)#通过phone库查询
try: #返回所有查询的信息
phone = info['phone']#手机号
province = info['province']#归属地:省份
city = info['city']#归属地,城市
zip_code = info['zip_code']#邮政编码
area_code = info['area_code']#区域编码
phone_type = info['phone_type']#手机号运营商
#print(phone+"\t"+province+city+"\t"+phone_type)
#return ("\n"+phone+" \t"+province+city+" \t"+phone_type)#因为我只需要手机号、区域、运营商,所以只返回这三个字段,其他字段,可以自己按需添加;
return (province+city)
except:#兼容查询失败的情况
print("\n"+str(phoneNum.strip("\n"))+" \t"+"Error!")
return ("\n"+str(phoneNum.strip("\n"))+" \t"+"Error!")
phoneNum = '19896***425'
info = getPhoneInfo(phoneNum)
info