服务器之家

服务器之家 > 正文

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

时间:2021-05-31 00:24     来源/作者:localhost1113

如下所示:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 获取微信群用户信息的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/localhost1113/article/details/79443292

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
2021德云社封箱演出完整版 2021年德云社封箱演出在线看
2021德云社封箱演出完整版 2021年德云社封箱演出在线看 2021-03-15
返回顶部