如何批量获取电话号码归属地,号码类型.
import pandas as pd
from phone import Phone
input_xlsx = pd.read_excel('mobile.xlsx')
class Mobile():
__files__ = 'kkk.xlsx'
def mobile(self):
li = []
for i in input_xlsx['mobile'].to_list():
data = Phone().find(str(i))
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):
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': '移动'
}