itchat操作微信
阿新 • • 發佈:2018-12-12
itchat
1、安裝
pip install itchat
2、簡單入門例項
有了itchat,如果你想要給檔案傳輸助手發一條資訊,只需要這樣:
import itchat
itchat.auto_login()
itchat.send('Hello, filehelper', toUserName='filehelper')
掃碼登陸
3、獲取男女比例
# 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)