python获取群成员信息

#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("交流群成员如下\n")
            for i in gsq['MemberList']:
                f.write('微信名:'+i['NickName']+'|群昵称:'+i['DisplayName']+'\n')
                print('微信名:'+i['NickName']+'|群昵称:'+i['DisplayName']+'\n')
            f.close()
if __name__ == '__main__':
    obj = WeChat()
    obj.get_all_info_from_wechat()

 

posted @ 2020-03-12 13:52  李先森°  阅读(958)  评论(0编辑  收藏  举报