0%
提取手机号
1 2 3 4 5 6 7
| import phonenumbers
txt = '我是xxx,今年x岁,电话是15332198671,我的朋友的电话是15311892310' m = phonenumbers.PhoneNumberMatcher(txt, 'CN')
for x in m: print(x.raw_string)
|
解析手机号
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import phonenumbers from phonenumbers import geocoder, carrier
phone1 = '+8615332198671'
phone1_obj = phonenumbers.parse(phone1)
phone2 = '15332198672'
phone2_obj = phonenumbers.parse(phone2, 'CN')
print(phonenumbers.is_possible_number(phone1_obj)) print(phonenumbers.is_possible_number(phone2_obj))
if phonenumbers.is_possible_number(phone1_obj): print(phone1_obj.country_code) print(phone1_obj.national_number) print(carrier.name_for_number(phone1_obj, 'zh')) print(geocoder.description_for_number(phone1_obj, 'zh'))
|