话不多说,直接上代码:
#!/user/bin/env python\
# -*- coding: utf-8 -*-
"""
@ Project: Wechat
@ File : getMessage.py
@ Author : Cheng
@ Data : 2019/5/2 23:53
@ Desc :
"""
import itchat
import data
#itchat.login()
itchat.auto_login(hotReload=True)
# 爬取自己好友相关信息, 返回一个json文件
friends = itchat.get_friends(update=True)[0:]
#计算好友个数
count = len(friends)
print('好友的个数为:', count)
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") # 男生是1,女生是2
Province = get_var("Province")
City = get_var("City")
Signature = get_var("Signature")
Framedata = {'NickName': NickName, 'Sex': Sex, 'Province': Province, 'City': City, 'Signature': Signature}
for i in Framedata.items():
print(i)
for i in range(len(friends)): #遍历字典的值
Framedata2 = {'NickName': NickName[i], 'Sex': Sex[i], 'Province': Province[i], 'City': City[i], 'Signature': Signature[i]}
print(Framedata2)