通过itchat模块查询微信的好友信息
再通过xlwt模块将数据解析后写入到execl表格中
注意:
1、qr_file 这个变量是存储execl表格的路径
2、微信需要能登录网页版,不能登录网页版无法登录
3、无法获取微信号,只能获取到基本信息
# -*- coding: utf-8 -*-
# author: Hermant_Tang
import itchat
import xlwt
import os
qr_file = r'D:\\test\\wechat'
work_book = xlwt.Workbook(encoding='utf-8')
seet = work_book.add_sheet('微信好友信息', 20)
itchat.auto_login(hotReload=True)
file_name = '微信好友信息.xls'
def create_execl():
a1 = ['City', 'PYQuanPin', 'RemarkPYInitial', 'Province', 'RemarkName', 'PYInitial', 'Signature', 'NickName',
'RemarkPYQuanPin', 'HeadImgUrl', 'Sex', 'UserName']
a2 = ['所属市', '好友微信名拼音', '好友备注拼音简称大写', '所属省', '备注', '微信名拼音大写', '个性签名', '微信名', '备注名拼音', '好友头像url', '性别', 'UserName']
for i in itchat.search_friends():
l = dict(zip(a1, a2)).get(i)
if l == 'UserName':
seet.write(0, 0, l)
elif l == '备注':
seet.write(0, 2, l)
elif l == '微信名':
seet.write(0, 1, l)
elif l == '备注名拼音':
seet.write(0, 9, l)
elif l == '好友微信名拼音':
seet.write(0, 7, l)
elif l == '好友备注拼音简称大写':
seet.write(0, 7, l)
elif l == '微信名拼音大写':
seet.write(0, 10, l)
elif l == '所属市':
seet.write(0, 5, l)
elif l == '所属省':
seet.write(0, 4, l)
elif l == '个性签名':
seet.write(0, 6, l)
elif l == '好友头像url':
seet.write(0, 11, l)
elif l == '性别':
seet.write(0, 3, l)
work_book.save(os.path.join(qr_file, file_name))
def insert_execl():
count = 1
for friend_info in itchat.get_friends():
for l in friend_info:
info = friend_info[l]
if l == 'UserName':
seet.write(count, 0, info)
elif l == 'RemarkName':
seet.write(count, 2, info)
elif l == 'NickName':
seet.write(count, 1, info)
elif l == 'RemarkPYQuanPin':
seet.write(count, 9, info)
elif l == 'PYQuanPin':
seet.write(count, 7, info)
elif l == 'RemarkPYInitial':
seet.write(count, 7, info)
elif l == 'PYInitial':
seet.write(count, 10, info)
elif l == 'City':
seet.write(count, 5, info)
elif l == 'Province':
seet.write(count, 4, info)
elif l == 'Signature':
seet.write(count, 6, info)
elif l == 'HeadImgUrl':
seet.write(count, 11, info)
elif l == 'Sex':
if info == 1:
seet.write(count, 3, '男')
elif info == 2:
seet.write(count, 3, '女')
else:
seet.write(count, 3, '未知')
count += 1
if __name__ == '__main__':
create_execl()
insert_execl()
work_book.save(os.path.join(qr_file, file_name))
print('数据导出完毕!!!!')