首页 > 微信 > 详细

python爬取所有微信好友的信息

时间:2018-05-01 19:14:57      阅读:288      评论:0      收藏:0      [点我收藏+]
‘‘‘
爬取所有T信好友的信息
‘‘‘
import itchat
from pandas import DataFrame

itchat.login()

friends=itchat.get_friends(update=True)[0:]

def get_var(var):
 variable=[]
 for i in friends:
  value=i[var]
  variable.append(value)
 return variable
 

NickName=get_var(‘NickName‘)
Sex=get_var(‘Sex‘)
Province=get_var(‘Province‘)
City=get_var(‘City‘)
Signature=get_var(‘Signature‘)

data={‘NickName‘:NickName,‘Sex‘:Sex,‘Province‘:Province,‘City‘:City,‘Signature‘:Signature}
frame=DataFrame(data)
frame.to_csv(‘data.csv‘,index=True,encoding="utf_8_sig")

计算微信好友男女比例:

import itchat
 
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:])
malecol=round(float(male)/total*100,2)
femalecol=round(float(female)/total*100,2)
othercol=round(float(other)/total*100,2)
print(‘男性朋友:%.2f%%‘ %(malecol)+‘\n‘+‘女性朋友:%.2f%%‘ % (femalecol)+‘\n‘+‘性别不明的好友:%.2f%%‘ %(othercol))
print("显示图如下:")

itchat的学习路径:https://itchat.readthedocs.io/zh/latest/

python爬取所有微信好友的信息

原文:https://www.cnblogs.com/zhouxinfei/p/8976771.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!