您的位置:首页 > 编程语言 > Python开发

使用python3获取微信好友并导入到excle中

2018-10-05 12:51 627 查看

import itchat

import xlwt

from time import time

itchat.auto_login(hotReload=True)

wbk = xlwt.Workbook()

sheet = wbk.add_sheet('sheet 1')

sheet.write(0, 0, '昵称')

sheet.write(0, 1, '备注')

sheet.write(0, 2, '性别')

sheet.write(0, 3, '签名')

sheet.write(0, 4, '城市')

friends = itchat.get_friends()[1:]

for index, friend in enumerate(friends):

    sheet.write(index + 1, 0, friend['NickName'])

    sheet.write(index + 1, 1, friend['RemarkName'])

    if friend['Sex'] == '1':

        sheet.write(index + 1, 2, '男')

    if friend['Sex'] == '2':

        sheet.write(index + 1, 2, '女')

    else:

        sheet.write(index + 1, 2, '未设置')

    sheet.write(index + 1, 3, friend['Signature'])

    sheet.write(index + 1, 4, friend['City'])

wbk.save(str(int(time())) + '.xls')

print('文件已经保存')

itchat.run()

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 微信库 excle