通过wxpy模块下载微信好友头像
注意:
1、qr_file是头像保存路径,需自定义
2、微信需要能够在网页登录
# -*- coding:utf-8
# author: HermanTang
import wxpy
import os
qr_file = r'D:\\test\\wechat\\images'
bot = wxpy.Bot(cache_path=True, qr_callback= qr_file, console_qr=0) #如果二维码在终端输出则将console_qr值修改为0
friends = bot.friends(update=True)
def friend_images():
"""
获取所有好友的头像
"""
for i in friends:
try:
print('{} 头像下载成功!!!!'.format(i.name))
i.get_avatar(os.path.join(qr_file, '{}.jpg'.format(i.name)))
except Exception as error:
print('哦吼!! {} 头像下载失败。。。。。'.format(i.name))
if __name__ == '__main__':
friend_images()