最近用闲余时间看了点python,在网上冲浪时发现有不少获取微信好友信息的博客,对此比较感兴趣,于是自己敲了敲顺便记录下来。

一、使用 wxpy 模块库获取好友男比例信息和城市分布。

# -*- coding: utf-8 -*-
"""
微信好友性别及位置信息
""" #导入模块
from wxpy import Bot '''Q
微信机器人登录有3种模式,
(1)极简模式:robot = Bot()
(2)终端模式:robot = Bot(console_qr=True)
(3)缓存模式(可保持登录状态):robot = Bot(cache_path=True)
'''
#初始化机器人,选择缓存模式(扫码)登录
robot = Bot(cache_path=True) #获取好友信息
robot.chats()
#robot.mps()#获取微信公众号信息 #获取好友的统计信息
Friends = robot.friends()
print(Friends.stats_text())

得到的好友信息结果

二、使用 itchat 获取好友详细信息并输出到记事本。

import itchat
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")
from pandas import DataFrame
data = {'NickName' : NickName,'Sex' : Sex,'Province' : Province,'City' : City,'Signature' : Signature}
frame = DataFrame(data)
frame.to_csv('myFriendanAlyze.txt',index=True)

这个就不展示了,大家想试的话扫描二维码登陆就可以看到自己好友的信息啦。

三、仅输出好友占比。

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:]) print("男性好友:" + str(male) + ",女性好友:" + str(female) + ",不明好友:"+str(other))

四、图表展示好友性别分布。

# -*- coding: utf-8 -*-
"""
Created at 2019-3-25 22:50:49
""" import itchat
import matplotlib.pyplot as plt
from collections import Counter
itchat.auto_login(hotReload=True)
friends = itchat.get_friends(update=True)
sexs = list(map(lambda x: x['Sex'], friends[1:]))
counts = list(map(lambda x: x[1], Counter(sexs).items()))
labels = ['Male','FeMale', 'Unknown']
colors = ['red', 'yellowgreen', 'lightskyblue']
plt.figure(figsize=(8, 5), dpi=80)
plt.axes(aspect=1)
plt.pie(counts, # 性别统计结果
labels=labels, # 性别展示标签
colors=colors, # 饼图区域配色
labeldistance=1.1, # 标签距离圆点距离
autopct='%3.1f%%', # 饼图区域文本格式
shadow=False, # 饼图是否显示阴影
startangle=90, # 饼图起始角度
pctdistance=0.6 # 饼图区域文本距离圆点距离
)
plt.legend(loc='upper right',)
plt.title('%s的微信好友性别组成' % friends[0]['NickName'])
plt.show()

Python 实现获取微信好友信息的更多相关文章

  1. Python之获取微信好友信息

    save_info.py: #!/usr/bin/python # -*- coding: UTF-8 -*- import itchat import pickle itchat.auto_logi ...

  2. python flask获取微信用户信息报404,nginx问题

    在学习flask与微信公众号时问题,发现测试自动回复/wechat8008时正常,而测试获取微信用户信息/wechat8008/index时出现404.查询资料后收发是nginx配置问题. 在loca ...

  3. Python使用itchat获取微信好友信息~

    最近发现了一个好玩的包itchat,通过调用微信网页版的接口实现收发消息,获取好友信息等一些功能,各位可以移步itchat项目介绍查看详细信息. 目标: 获取好友列表 统计性别及城市分布 根据好友签名 ...

  4. python之获取微信好友列表并保存文档中

    代码如下 from wxpy import * from pprint import pprint #登录微信 bot = Bot() my_friend = bot.friends() f = op ...

  5. python flask获取微信用户信息流程

    需要了解的几个url 用户第一次访问时的url,包含以下几个参数 https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID& ...

  6. python itchat 爬取微信好友信息

    原文链接:https://mp.weixin.qq.com/s/4EXgR4GkriTnAzVxluJxmg 「itchat」一个开源的微信个人接口,今天我们就用itchat爬取微信好友信息,无图言虚 ...

  7. Python爬取微信好友

    前言 今天看到一篇好玩的文章,可以实现微信的内容爬取和聊天机器人的制作,所以尝试着实现一遍,本文记录了实现过程和一些探索的内容 来源: 痴海 链接: https://mp.weixin.qq.com/ ...

  8. SpringBoot中获取微信用户信息从未如此简单!

    前言 不知道你是否参加过拼多多上邀请微信好友砍价功能,这个功能实现首先需要考虑的就是获取微信用户的信息.获取用户信息就是获取公众号下微信用户的信息,今天我就来讲讲如何从公众号下获取微信用户信息. 需要 ...

  9. Magicodes.WeiChat——使用OAuth 2.0获取微信用户信息

    使用Magicodes.WeiChat,可以很方便的获取到微信用户的信息.在使用OAuth 2.0之前,你先需要做以下操作: 1)在开发者中心修改[网页授权获取用户基本信息],在弹出的界面输入自己的根 ...

随机推荐

  1. mac抓包工具anyproxy

    本文以 mac为代理,ios手机为客户端举例. 文档地址:http://anyproxy.io/ 1.环境配置: 安装  node  :参考   https://www.jianshu.com/p/3 ...

  2. flink学习

    flink介绍: Apache Flink is an open source platform for distributed stream and batch data processing. F ...

  3. vue中使用postMessage进行跨越传值

    想在“当前位置”获取子页面的title属性,但是main页面和子页面在不同的端口上,直接获取会出现: “Blocked a frame with origin from accessing a cro ...

  4. python3.X中try/except

    包含try...except...在3.x版本中与2.x版本中的用法差异. 1.先说差异: 在2.x的python中用法实例: try: ...... except Exception,e: rais ...

  5. python3中列表、元组、字典的增删改查说明详解

    python基础中的列表.元组.字典属于python中内置的序列数据结构.其中序列可以进行的操作包括索引.截取(切片).加.乘.成员检查等. 1.列表 列表(list)是最常用的python数据类型之 ...

  6. 学习随笔:Vue.js与Django交互以及Ajax和axios

    1. Vue.js地址 Staticfile CDN(国内): https://cdn.staticfile.org/vue/2.2.2/vue.min.js unpkg:会保持和npm发布的最新的版 ...

  7. 页面跳转之session

    题意:设主页为index.jsp 通过session将index.jsp中的信息传送给结果页面result.jsp.(其实,session的生命周期是整个服务器开启过程,具体不做详细介绍).这个 其实 ...

  8. json字符串的拼接

    关于json字符串的解析与拼接,第一次接触,留下个笔记了.......解析,是改的代码,拼接是纯的,解析就不说了,笔记一下拼接了 关于解析主要分三部分,一个是第一层处理,一个是第二层处理,一个是进行& ...

  9. nginx 静态目录配置规则

    1.子目录匹配 如下配置 location / { root /data/www; } 访问http://127.0.0.1/时,配匹配/data/www 访问http://127.0.0.1/ima ...

  10. java中class文件与jar文件

    1. JAR 文件包 JAR 文件就是 Java Archive File,顾名思意,它的应用是与 Java 息息相关的,是 Java 的一种文档格式.JAR 文件非常类似 ZIP 文件——准确的说, ...