Python 实现获取微信好友信息
最近用闲余时间看了点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 实现获取微信好友信息的更多相关文章
- Python之获取微信好友信息
save_info.py: #!/usr/bin/python # -*- coding: UTF-8 -*- import itchat import pickle itchat.auto_logi ...
- python flask获取微信用户信息报404,nginx问题
在学习flask与微信公众号时问题,发现测试自动回复/wechat8008时正常,而测试获取微信用户信息/wechat8008/index时出现404.查询资料后收发是nginx配置问题. 在loca ...
- Python使用itchat获取微信好友信息~
最近发现了一个好玩的包itchat,通过调用微信网页版的接口实现收发消息,获取好友信息等一些功能,各位可以移步itchat项目介绍查看详细信息. 目标: 获取好友列表 统计性别及城市分布 根据好友签名 ...
- python之获取微信好友列表并保存文档中
代码如下 from wxpy import * from pprint import pprint #登录微信 bot = Bot() my_friend = bot.friends() f = op ...
- python flask获取微信用户信息流程
需要了解的几个url 用户第一次访问时的url,包含以下几个参数 https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID& ...
- python itchat 爬取微信好友信息
原文链接:https://mp.weixin.qq.com/s/4EXgR4GkriTnAzVxluJxmg 「itchat」一个开源的微信个人接口,今天我们就用itchat爬取微信好友信息,无图言虚 ...
- Python爬取微信好友
前言 今天看到一篇好玩的文章,可以实现微信的内容爬取和聊天机器人的制作,所以尝试着实现一遍,本文记录了实现过程和一些探索的内容 来源: 痴海 链接: https://mp.weixin.qq.com/ ...
- SpringBoot中获取微信用户信息从未如此简单!
前言 不知道你是否参加过拼多多上邀请微信好友砍价功能,这个功能实现首先需要考虑的就是获取微信用户的信息.获取用户信息就是获取公众号下微信用户的信息,今天我就来讲讲如何从公众号下获取微信用户信息. 需要 ...
- Magicodes.WeiChat——使用OAuth 2.0获取微信用户信息
使用Magicodes.WeiChat,可以很方便的获取到微信用户的信息.在使用OAuth 2.0之前,你先需要做以下操作: 1)在开发者中心修改[网页授权获取用户基本信息],在弹出的界面输入自己的根 ...
随机推荐
- Servlet校验密码之Mariadb篇
Servlet校验密码之Mariadb篇 先放图-- 数据库: 效果图: 整体来说与上一篇差距不大,这次主要是采用数据库来进行校验,我使用的是Mariadb,安装与配置不用我说 主要有一点,导入连接器 ...
- supermap中预览osgb格式的倾斜摄影文件
参考: https://zhidao.baidu.com/question/136723493545478005.html 使用的是SuperMap IDesktop 9D,操作方法如下: 打开超图, ...
- 强制.net 程序以32位模式运行
You can modify the PE header of the executable (using the "Corflags.exe" .NET Framework SD ...
- Codeforces 581F Zublicanes and Mumocrates 树形dp
Zublicanes and Mumocrates dp[ i ][ j ][ k ] 表示 以 i 为根的子树, 占领 i 的 是 j 并且第一个人占了 i 子树的 k 个叶子节点的最小值. 然后随 ...
- python--random库基本介绍
random库是使用随机数的Python标准库 python中用于生成伪随机数的函数库是random 因为是标准库,使用时候只需要import random random库包含两类函数,常用的共9个 ...
- Anconda 3.7安装以及使用详细教程
Anconda 3.7安装以及使用详细教程 2019-04-17 22:42:03 一.下载anconda 3.7 链接地址:官方地址 二.安装 双击下载好的Anaconda3-2019.03- ...
- mongodbwindows安装过程附带安装包百度云
1.mongodb安装包链接 链接:https://pan.baidu.com/s/1bxZ2oV-iJEs7RoH5kN6jVg 密码:ajuj 2.配置准备,创建文件夹及文件: 目录为: \ ...
- ubuntu系统下matplotlib中文乱码问题
参考 [ubuntu系统下matplotlib中文乱码问题 - CSDN博客](https://blog.csdn.net/jeff_liu_sky_/article/details/54023745 ...
- CentOS7终端的分辨率和字体修改
本文转贴自https://blog.csdn.net/u010566813/article/details/40502819 一.修改分辨率 修改/boot/grub2/grub.cfg 添加如上,具 ...
- [微信跳转链接]之WAP跳转微信内指定页面
由于微信覆盖太全面了,几乎所有人都使用微信APP,但是对于做产品的公司来说,所有的产品几乎都离不开微信的推广,然而微信属于封闭式的一个社交应用,大部分只能在今日头条,百度,等等...如果你在推广页面上 ...