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

作者:localhost1113 时间:2022-11-09 18:15:41 

如下所示:


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)

来源:https://blog.csdn.net/localhost1113/article/details/79443292

标签:python,itchat,微信群,信息
0
投稿

猜你喜欢

  • selenium鼠标操作实战案例详解

    2023-09-18 04:08:40
  • 使用Python编写一个简单的tic-tac-toe游戏的教程

    2021-01-26 04:27:43
  • Python2和Python3中print的用法示例总结

    2022-07-19 02:27:58
  • Python中无限循环需要什么条件

    2023-03-28 09:05:14
  • Python实现高斯函数的三维显示方法

    2023-07-04 01:47:22
  • Python RuntimeError: thread.__init__() not called解决方法

    2022-12-22 17:11:46
  • ORACLE 最大连接数的问题

    2009-07-23 14:27:00
  • Oracle 语句优化分析说明第1/2页

    2009-09-18 13:23:00
  • Python3 列表,数组,矩阵的相互转换的方法示例

    2023-05-30 23:52:19
  • 全透视:CSS Z-index 属性

    2009-09-21 12:52:00
  • python去除字符串中空格的6种常用方法

    2023-09-25 12:36:53
  • elementUI el-table二次封装的详细实例

    2024-05-03 15:12:00
  • Python同步遍历多个列表的示例

    2023-08-08 00:20:10
  • 解析PHP中一些可能会被忽略的问题

    2023-09-05 14:07:37
  • golang判断net.Conn 是否已关闭的操作

    2024-04-30 10:07:02
  • python3实现的zip格式压缩文件夹操作示例

    2023-07-31 18:17:48
  • vue相关配置文件详解及多环境配置详细步骤

    2023-07-02 16:39:39
  • php中get_meta_tags()、CURL与user-agent用法分析

    2024-05-02 17:32:52
  • Python 使用类写装饰器的小技巧

    2022-09-16 05:54:08
  • 提高MySQL数据库查询效率的三个实用技巧

    2008-12-03 16:40:00
  • asp之家 网络编程 m.aspxhome.com