Skip to content

aimer1124/WeChatData

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WeixinData

Use Python to deal Weixin Data

第三步,获取微信中所有好友的签名,将签名的内容进行词云分析

  • 获取好友中的签名信息
signature = i["Signature"].replace(" ", "").replace("span", "").replace("class", "").replace("emoji", "")
  • 使用jieba分词
wordlist_jieba = jieba.cut(text, cut_all=True)
wl_space_split = " ".join(wordlist_jieba)
  • 使用wordcloud词云进行词云处理
my_wordcloud = WordCloud(font_path='/Users/yjshi/Library/Fonts/arialuni.ttf').generate(wl_space_split)
plt.imshow(my_wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()

如果有中主语言需要使用词云时,需要修改wordcloud的默认字体。默认字体是不支持中文字符的.

font_path='/Users/yjshi/Library/Fonts/arialuni.ttf'
  • 查看生成的词云图

词云图

  • 使用指定的图片,生成词云图

    • 原图

    原图

    • 词云图

    词云图

d = os.path.dirname(__file__)
alice_coloring = np.array(Image.open(os.path.join(d, "pic.png")))
my_wordcloud = WordCloud(background_color="white", max_words=2000, mask=alice_coloring,max_font_size=40, random_state=42,font_path='/Users/yjshi/Library/Fonts/arialuni.ttf').generate(wl_space_split)
image_colors = ImageColorGenerator(alice_coloring)
plt.imshow(my_wordcloud.recolor(color_func=image_colors))
plt.imshow(my_wordcloud)
plt.axis("off")
plt.show()

第二步,获取微信好友中,男女比例

  • 获取好友列表
itchat.get_friends()
  • 分析微信好友数据结构

好友数据结构

  • 从数据结构可以看出,如果想获取性别,只需要读取sex字段的值
for i in friends[1:]:
    sex = i["Sex"]
    if sex == 1:
        male += 1
    elif sex == 2:
        female += 1
    else:
        other += 1
  • 查看的所有好友的性别分布
男性好友:61.67%
女性好友:32.62%
其他:5.71%

第一步,调用微信登录,实现微信消息发送

import itchat
itchat.login()# 发送消息
itchat.send(u'你好', 'filehelper')

实现流程

  1. 生成微信登录二微码图片
  2. 保存至本机
  3. 自动打开登录二微码图片
  4. 手机扫描微信二微码图片,实现网页版微信登录
  5. 登录成功后,会删除本机的微信登录二微码
  6. 给手机端微信发送消息你好

实现原理

  1. itchat 会模拟手机版本的微信,获取登录二微码
  2. 通过扫描二维码后,手机登录,登录后可使用微信网页版本的功能

核心实现代码itchat/components/login.py


参考资料

About

Use Python to deal WeChat Data

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages