欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

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

时间:2020-11-09 18:28:43|栏目: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实现逻辑回归的方法示例

栏    目:Python代码

下一篇:pandas取出重复数据的方法

本文标题:python-itchat 获取微信群用户信息的实例

本文地址:http://www.codeinn.net/misctech/20787.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有