True White | teach you a step by step analysis of micro-letter friends crawling in Python

Copyright: please indicate the source https://blog.csdn.net/EdwardDrew/article/details/85205644

Foreword

Some time ago the company a colleague made pictures in the group, is the micro-channel all his friends head makes up a large map, I looked quite interesting, and he wanted to do it, then Baidu how to crawl under the micro-letter friends like ...... a full search crawl with Python, Python reptile heard that before, but not how contact with Python, be white ( true white ). But I do not panic, whatever the outcome, he is a computer professional (and now do is to Java development), the principle of language should be figured in, so I probably read the introduction and basic grammar at Python, and then under his own fiddle with Python write helloWord, ah, I feel very simple ah! But I want to go and get yourself a step by step? nonexistent

Found a lot of articles like how to crawl analysis of the micro-letter friends, feeling a little Python is not really the foundation can not read, but it is too cumbersome a person, eventually Google an article more suitable for white users operation, It will be mentioned below. But for true white (people who know nothing about Python is still a bit difficult), because for us this layman, I just want to operate the software as simple a few clicks to get the result I wanted, and I am do not want to waste the time to understand what the principles of what Python what the installation environment, barabara ...... so there is this blog, without further ado, the following entry to the topic

Note: This blog do not speak principle (because I do not know, ha ha), we talk about the implementation process, the principle of the venue below please refer to

text

effect

To practice magic, will look at the effect ......
1: Friends of gender statistics
Python results of data analysis - gender statistics .png
seem to female ratio is almost ah

2: Statistics Friends geographical distribution and visual display on a map
Python resulting data analysis - .png area
the most Cantonese, our department Cantonese

3: make friends nickname word cloud

Because this information is relatively private, do not show here. Word cloud analysis with friends following the signature of the show similar results, using the same technology

4:统计好友个性签名中的高频词汇
Python results of data analysis - signature word cloud .png
中间最大的几个英文,class、span、emoji应该是一些特殊字符或表情显示不出来。出现比较多的词,比如努力、生活、自己、人生,出现次数越多字越大

5:将所有好友的头像合并成一张大图

本人没有获取好友的同意,头像算隐私了吧?所以打了马赛克(谁还没有一点小秘密呢?)

Python results of data analysis - Picture synthesis .png
啊,我的眼睛……

安装Python环境

1、打开Python官网,下载最新版Python3.7.1安装,如下图。

懒得去官网的点这里直接下载链接

Python install 1.png
2、 下载完之后双击python-3.7.1.exe,勾选Add python.exe to Path(是把Python的安装路径添加到系统环境变量的Path变量中,很重要。大神可忽略,小白必选),点击Install Now(默认安装到C盘,可以自己选择安装目录,由于我的C盘是固体250G,所以就默认安装),如下图
Python install 2.png
3、安装完之后检查下,点击开始,输入cmd(或者win+R快捷键)打开命令行窗口,输入python,出现下图就说明安装成功。此时输入exit()可以离开python编译器。
Python installation 3.png

安装依赖

在cmd窗口下运行

  • pip3 install pillow

然后就开始安装,等到安装完成之后才可再次输入命令(耐心等,这一过程不要乱动,小白双手可离开键盘),如下图
Python install the relevant plug-.png

类似的依次运行下面命令

  • pip3 install pyecharts
  • pip3 install itchat
  • pip3 install jieba
  • pip3 install echarts-china-provinces-pypkg
  • pip3 install echarts-countries-pypkg

下载源码

懂github的

真小白

下载之后放到一个地方,然后解压,如下图
Python installation source .png

运行

准备好所有东西之后就可以正式开始抓取微信好友信息了

获取用户信息

1、需要将get_user_info.py第70行的二胖,改成自己的名字(这里我改成自己的微信昵称:鲜花)。

用什么软件打开修改?我用的是notepad++(百度下载就行),或者直接用文本text软件notepad.exe打开也行,不过格式不好看

Python source code to run 1.png

2、定位到源码根目录下,cd /d F:\Projects\python\wechat_friends-master(替换成你自己的)或者在源码根目录下按住Shift+鼠标右键,选择在此处打开命令窗口,如下图
Python source code to run 2.png

3、输入python get_user_info.py,(如果安装了多个python环境的输入python3 get_user_info.py), 执行后会弹出微信网页版登录的二维码,用手机微信扫一扫并且同意登录即可(如果图片没弹出来,在源码根目录下找到QR.png,手动点击打开),如下图:
Python run 2.png

Python source code to run 3.png

命令执行后,等待,出现下图说明已登录成功并获取到了好友的信息
Python source code to run 4.png

python get_user_info.py执行后

  • 会在data目录下生成friends.json (存放抓取到的好友信息,比如昵称、头像链接、个性签名等)
  • 会在images目录下存放所有好友的头像
    如下图
    Python running result file - Friends Information .png
    Python running result file - .png,

到此,我们的好友数据拿到了,下面就是对数据进行可视化分析

数据可视化分析

在cmd命令窗口中按住Win+C键结束命令,输入python analyse.py,(如果安装了多个python环境的输入python3 analyse.py),数据处理过程需要点时间(等待吧),如下图
Python source code to run 5.png
当出现如下图时说明处理完成了
Python source code to run 6.png

python analyse.py 执行后会在analyse文件夹下生产合成后的图片以及可视化的文件,如下图
Run Python result files - data analysis .png

至此,大功告成,去看看我们自己的好友分析吧,点开html文件即可用浏览器访问

总结

周六早上捣鼓了下这个微信好友分析,顺便写了一篇博客,感想如下

  • 完事开头难,你去做了其实也就那样
  • 写详细的博客真心累(小白笑了,大神呵呵)
  • Thanks to two fat (Benpian micro-channel analysis of the source code of the original author friend, beneath the venue and want to learn more about the reference )

reference

Share a piece of code - analysis of micro-letter friends


Please pay attention to more exciting articles

Guess you like

Origin blog.csdn.net/EdwardDrew/article/details/85205644