python-itchat 获取微信群用户信息的实例

yipeiwu_com5年前Python基础

如下所示:

import itchat, time
from itchat.content import TEXT
#name = ' '
roomslist = []

itchat.auto_login(enableCmdQR = False)

def getroom_message(n):
  #获取群的username,对群成员进行分析需要用到
  itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊
  RoomList = itchat.search_chatrooms(name=n)
  if RoomList is None:
    print("%s group is not found!" % (name))
  else:
    return RoomList[0]['UserName']

def getchatrooms():
  #获取群聊列表
  roomslist = itchat.get_chatrooms()
  #print(roomslist)
  return roomslist



for i in getchatrooms():
  #print(i['NickName'])
  roomslist.append(i['NickName'])

with open('群用户名.txt', 'a', encoding='utf-8')as f:
  for n in roomslist:
    ChatRoom = itchat.update_chatroom(getroom_message(n), detailedMember=True)
    for i in ChatRoom['MemberList']:
      #print (i['Province']+":",i['NickName'])
      f.write(i['Province']+":"+i['NickName']+'\n')
      print('正在写入      '+i['Province']+":",i['NickName'])
  f.close()

# for i in ChatRoom:
#   print(i['MemberList']['ContactList'])
#   count += 1
# print(count)

# # @itchat.msg_register(TEXT)
# # def simple_reply(TEXT):
# #   print(msg.text)
# #
# # itchat.auto_login(enableCmdQR = False,hotReload = True) # enableCmdQR=True这一参数为二维码在下面控制台中显示出来,而不是用图片显示
# # itchat.run()
# itchat.auto_login(enableCmdQR = False)
#
# # time.sleep()
# # itchat.logout()
# # friends = itchat.get_friends()
# # for i in friends:
# #   print(i)
# rooms = itchat.get_chatrooms()
# for i in rooms:
#   print(i['NickName'])
#   memberList = itchat.update_chatroom(i['NickName'])
#   print (memberList)
#
# #   room = itchat.update_chatroom(i['NickName'],detailedMember = True)
# #   print(room)
# #   # for i in room:
# #   #   print(i)

以上这篇python-itchat 获取微信群用户信息的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python距离测量的方法

之所以写这个,其实就是希望能对距离有一些概念,当然这个也是很基础的,不过千里之行始于足下嘛,各种路径算法,比如a*什么的都会用到这个 距离测量有三种方式 1、欧式距离,这个是最常用的距离...

python导入csv文件出现SyntaxError问题分析

背景 np.loadtxt()用于从文本加载数据。 文本文件中的每一行必须含有相同的数据。 *** loadtxt(fname,dtype=<class'float'>,co...

python正向最大匹配分词和逆向最大匹配分词的实例

正向最大匹配 # -*- coding:utf-8 -*- CODEC='utf-8' def u(s, encoding): 'converted other enco...

python的re模块使用方法详解

一、正则表达式的特殊字符介绍 正则表达式 ^ 匹配行首 $ 匹配行尾 . 任意...

python3+PyQt5图形项的自定义和交互 python3实现page Designer应用程序

python3+PyQt5图形项的自定义和交互 python3实现page Designer应用程序

本文通过Python3+PyQt5实现《python Qt Gui 快速编程》这本书的page Designer应用程序,采用QGraphicsView,QGraphicsScene,Q...