获取微信好友头像
import itchat
'''
获取微信好友头像
'''
# 登录微信
itchat.auto_login(hotReload=True)
# 获取微信好友列表
for friend in itchat.get_friends():
# print(friend)
# print(friend['RemarkName'], friend(['NickName'], friend['Sex']))
img = itchat.get_head_img(userName=friend['UserName'])
path = 'D:\python\study\itchat\head_img\\' + friend['UserName'] + '.jpg'
with open(path, 'wb') as f:
f.write(img)
itchat.run()
统计好友的男女比例
import itchat
itchat.auto_login()
# 1.统计好友的男女比例
# 说明:friends是一个字典
friends = itchat.get_friends(hotReload=True)
info = {}
# 列表切片[1,2,3,4] => [1:] => [2,3,4]
for friend in friends[1:]:
# 男
if friend['Sex'] == 1:
info['male'] = info.get('male', 0) + 1
# 女
elif friend['Sex'] == 2:
info['female'] = info.get('female', 0) + 1
# 性别未知
else:
info['other'] = info.get('other', 0) + 1
print(info)