使用Python中的itchat导出微信好友的信息

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014094101/article/details/82389840

直接上代码:

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

猜你喜欢

转载自blog.csdn.net/u014094101/article/details/82389840