欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

根据电话号码获取归属地

程序员文章站 2022-03-03 10:20:23
...
from phone import Phone
def getlocation(num):
    if ';' in num:
        nums=num.split(';')
        for i in nums:
            if len(str(i))==11:
                try:
                    info=Phone().find(i)
                    city = info['city']
                    return city 
                except Exception as e:
#                     print(e)
                    return ""
    else:
         if len(str(num))==11:
                try:
                    info=Phone().find(num)
                    city = info['city']
                    return city 
                except Exception as e:
#                     print(e)
                    return ""