使用itchat库导出微信联系人头像,并保存至指定位置

# -*- coding: utf-8 -*-
import itchat

# 用于二维码登录微信,
itchat.auto_login()
# 获取通讯录
for friend in itchat.get_friends(update=True)[0:]:
    # print(friend['NickName'])
#    print(friend['NickName'])
    img = itchat.get_head_img(userName=friend["UserName"])
    # 保存头像的地址
    path = "py_img" + friend['NickName'] + "(" + friend['RemarkName'] + ").jpg"
    try:
        with open(path, 'wb') as f:
            f.write(img)
    except Exception as e:
        print(repr(e))
# 登出
itchat.run()

 

你可能感兴趣的:(python练习)