欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-06 09:07:14
如下所示: import itchat, time from itchat.content import text #name = ' ' roomslis...

如下所示:

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 获取微信群用户信息的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。