2020-12-04

如何批量获取电话号码归属地,号码类型.

import pandas as pd
from phone import Phone #需要自己安装Phone这个库
input_xlsx = pd.read_excel('mobile.xlsx') #批量获取电话号码
# input_xlsx.head()

class Mobile():
    __files__ = 'kkk.xlsx' #Excel文件名

    def mobile(self):
        li = []
        for i in input_xlsx['mobile'].to_list(): #获取电话号码那一列字段转换成list格式
            data = Phone().find(str(i)) #因为Excel文件里面有空的电话号码,用try-except方法进行处理
            try:
                phone = data['phone']
                province = data['province']
                city = data['city']
                zip_code = data['zip_code']
                area_code = data['area_code']
                phone_type = data['phone_type']
                status = '1'
                list_datas = [phone, province, city, zip_code, area_code, phone_type, status]
                li.append(list_datas)
            except:
                phone = 0
                province = 0
                city = 0
                zip_code = 0
                area_code = 0
                phone_type = 0
                status = 0
                list_datas = [phone, province, city, zip_code, area_code, phone_type, status]
                li.append(list_datas)

        return li

    def write_excel_pd(self): #将所获取的电话号码写到原Excel表格中
        datas = self.mobile()
        df1 = pd.DataFrame(datas)
        writer = pd.ExcelWriter(self.__files__)
        df1.to_excel(excel_writer=writer, sheet_name="电话号码", index=False)
        writer.save()
        writer.close()
        print("文件生成成功")
#
if __name__ == "__main__":
    a = Mobile()
    a.write_excel_pd()
样例子
{
 'phone': '888888888', 
 'province': '北京',
 'city': '北京',
 'zip_code': '100000',
 'area_code': '010',
 'phone_type': '移动'
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值