Python实践-itchat获取微信好友总人数以及男女比例
itchat
pip install itchat
有了itchat,如果你想要给文件传输助手发一条信息,只需要这样:
import itchat
itchat.auto_login()
itchat.send('Hello, filehelper', toUserName='filehelper')
扫码登陆
# coding=utf-8
import itchat, time
itchat.login()
# 微信好友男女比例分析
friends = itchat.get_friends(update=True)[0:]
male = female = other = 0
for i in friends[1:]:
sex = i["Sex"]
if sex == 1:
male += 1
elif sex == 2:
female += 1
else:other += 1
total = len(friends[1:])
print("男性好友: %.2f%%" % (float(male) / total * 100) + "\n"
+ "女性好友: %.2f%%" % (float(female) / total * 100) + "\n"
+ "性别不明: %.2f%%" % (float(other) / total * 100))
print("好友数量: ",male+female+other)
print("男性好友: ",male)
print("女性好友: ",female)
print("性别不明: ",other)