from phone import Phone
# 合法判断
phone_prefix = ['130', '131', '132', '155', '156', '185', '186', '145', '176',
'134', '135', '136', '137', '138', '139', '147', '150', '151',
'152', '157', '158', '159', '178', '182', '183', '184', '187',
'188', '133', '153', '189']
def phone_check(phone_num):
if len(phone_num) != 11:
return "电话号码非法的,长度应该是11位!"
else:
if phone_num.isdigit():
if phone_num[:3] in phone_prefix:
return "电话号码是合法的"
else:
return "电话号码是非法的,号码前三位不是合法的号段!"
else:
return "电话号码应该全部由数字构成!"
# 归属地查询
def get_phone_info(phone_num):
phone_info = Phone().find(phone_num)
try:
phone = phone_info['phone']
province = phone_info['province'] #所在省份
city = phone_info['city'] #所在城市
zip_code = phone_info['zip_code'] #所在城市邮编
area_code = phone_info['area_code'] #所在城市区号
phone_type = phone_info['phone_type'] #号码运营商
except:
print('无效号码')
return phone, province, city, zip_code, area_code, phone_type
phone = input("请输入手机号:")
test = get_phone_info(phone)
print(test)
电话号归属地查询(携号转网除外)
猜你喜欢
转载自blog.csdn.net/u013080870/article/details/125996523
今日推荐
周排行