python-itchat 获取微信群用户信息的实例
如下所示:
importitchat,time
fromitchat.contentimportTEXT
#name=''
roomslist=[]
itchat.auto_login(enableCmdQR=False)
defgetroom_message(n):
#获取群的username,对群成员进行分析需要用到
itchat.dump_login_status()#显示所有的群聊信息,默认是返回保存到通讯录中的群聊
RoomList=itchat.search_chatrooms(name=n)
ifRoomListisNone:
print("%sgroupisnotfound!"%(name))
else:
returnRoomList[0]['UserName']
defgetchatrooms():
#获取群聊列表
roomslist=itchat.get_chatrooms()
#print(roomslist)
returnroomslist
foriingetchatrooms():
#print(i['NickName'])
roomslist.append(i['NickName'])
withopen('群用户名.txt','a',encoding='utf-8')asf:
forninroomslist:
ChatRoom=itchat.update_chatroom(getroom_message(n),detailedMember=True)
foriinChatRoom['MemberList']:
#print(i['Province']+":",i['NickName'])
f.write(i['Province']+":"+i['NickName']+'\n')
print('正在写入'+i['Province']+":",i['NickName'])
f.close()
#foriinChatRoom:
#print(i['MemberList']['ContactList'])
#count+=1
#print(count)
##@itchat.msg_register(TEXT)
##defsimple_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()
##foriinfriends:
##print(i)
#rooms=itchat.get_chatrooms()
#foriinrooms:
#print(i['NickName'])
#memberList=itchat.update_chatroom(i['NickName'])
#print(memberList)
#
##room=itchat.update_chatroom(i['NickName'],detailedMember=True)
##print(room)
###foriinroom:
###print(i)
以上这篇python-itchat获取微信群用户信息的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。