神奇的库 phone

Python(phone) 可以获取 手机的归属地,区号,运营商等

 

Python(phone)模块获取手机号归属地、区号、运营商等

 

一、我使用的是python3,可以自行搜索下载

 

二、安装phone模块, 

pip install phone 

 

三、测试代码如下:

 
from phone import Phone

if __name__ == "__main__":
    phoneNum = '17613394466'
    info = Phone().find(phoneNum)
    print(info)
    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']
    except:
        print('none')
 

四、批量查询excle中已有的电话号

 
from phone import Phone
import xlrd
import xlwt


def Get_Excel_data():
    file = './Tel.xlsx'   #电话号码存储的excle表
    re1 = xlrd.open_workbook(file)

    outwb = xlwt.Workbook() #创建工作簿
    # print(type(outwb))
    outws = outwb.add_sheet("new")  #在工作簿中新建一个工作表new
    # print(type(outws))

    # 读取第一个sheet
    ws = re1.sheet_by_index(0)
    rows = ws.nrows
    # print(rows)
    outws.write(0, 0, u'电话号')  #给新表的第一行添加对应的标签
    outws.write(0, 1, u'省份')
    outws.write(0, 2, u'城市')
    outws.write(0, 3, u'区号')
    outws.write(0, 4, u'运营商')

    for i in range(0, rows):
        Telvalue = int(ws.cell_value(i, 0))
        # print(Telvalue)
        data = Phone().find(Telvalue)
        print(data)
        outws.write(i + 1, 0, Telvalue)  #给新表的个列添加对应的数据
        try:
            outws.write(i + 1, 1, data['province'])
            outws.write(i + 1, 2, data['city'])
            outws.write(i + 1, 3, data['area_code'])
            outws.write(i + 1, 4, data['phone_type'])

            outwb.save(r'New_Tel.xls')
        except:
            print("none")

Get_Excel_data()
 
posted @ 2022-03-01 18:10  rianley  阅读(211)  评论(0编辑  收藏  举报