关于人工智能:Pythonphone模块获取手机号归属地区号运营商等

43次阅读

共计 1218 个字符,预计需要花费 4 分钟才能阅读完成。

一、我应用的是 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()

举荐浏览:

https://mp.weixin.qq.com/s/dV2JzXfgjDdCmWRmE0glDA

https://mp.weixin.qq.com/s/an83QZOWXHqll3SGPYTL5g

正文完
 0