#coding: utf-8 import itchat,datetime from itchat.content import TEXT itchat.auto_login(hotReload=True)#不需要重复扫码登录 class WeChat(object): def get_all_info_from_wechat(self): # itchat.auto_login(enableCmdQR = False) #获取群 roomslist = itchat.get_chatrooms() #群名称 itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 myroom=itchat.search_chatrooms(name=u'交流群') #群聊名称 gsq=itchat.update_chatroom(myroom[0]['UserName'], detailedMember=True) with open('群用户名.txt','w',encoding='utf-8')as f: f.write("交流群成员如下 ") for i in gsq['MemberList']: f.write('微信名:'+i['NickName']+'|群昵称:'+i['DisplayName']+' ') print('微信名:'+i['NickName']+'|群昵称:'+i['DisplayName']+' ') f.close() if __name__ == '__main__': obj = WeChat() obj.get_all_info_from_wechat()