先发代码
import itchat
itchat.login()
friends = itchat.get_friends(update=True)[:]
total = len(friends) - 1
man = women = other = 0
itchat.login()
friends = itchat.get_friends(update=True)[:]
total = len(friends) - 1
man = women = other = 0
for friend in friends[0:]:
sex = friend["Sex"]
if sex == 1:
man += 1
elif sex == 2:
women += 1
else:
other += 1
sex = friend["Sex"]
if sex == 1:
man += 1
elif sex == 2:
women += 1
else:
other += 1
print (total)
print("男性好友:%.2f%%" % (float(man) / total * 100))
print("女性好友: %.2f%%" % (float(women) / total * 100))
print("其他:%.2f%%" % (float(other) / total * 100))
print("男性好友:%.2f%%" % (float(man) / total * 100))
print("女性好友: %.2f%%" % (float(women) / total * 100))
print("其他:%.2f%%" % (float(other) / total * 100))
需要首先 pip install itchat
登陆 QR CODE后即可统计出结果。
如下: