Python (phone) module obtains the location, area code, operator, etc. of the mobile phone number

Python (phone) module obtains the location, area code, operator, etc. of the mobile phone number

1. I am using python3, you can search and download by yourself

2. Install the phone module, pip install phone 

3. The test code is as follows:

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')

4. Batch query existing phone numbers in excel

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()

Guess you like

Origin blog.csdn.net/u010671061/article/details/81177976