微信给python语言提供了一个接口,我们可以借助着个接口得已更好的分析处理各种信息,更好的管理好自己的微信号
好友、群聊、公众号信息提供常见的操作函数:
函数 | 说明 |
---|---|
get_contact | 获取微信群聊信息 |
get_chatrooms | 与 contact作用一样 |
get_friends | 获取好友信息 |
get_maps | 获取公众号 |
login | 登录函数 |
auto_login | 自动登录 |
loginout | 退出登录 |
import itchat #导入itchat???print(dir(itchat)) #查看itchat属性
['Core', 'VERSION', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'add_friend', 'add_member_into_chatroom', 'auto_login', 'check_login', 'components', 'config', 'configured_reply', 'content', 'core', 'create_chatroom', 'delete_member_from_chatroom', 'dump_login_status', 'get_QR', 'get_QRuuid', 'get_chatrooms', 'get_contact', 'get_friends', 'get_head_img', 'get_mps', 'get_msg', 'instanceList', 'load_login_status', 'log', 'login', 'logout', 'msg_register', 'new_instance', 'originInstance', 'returnvalues', 'revoke', 'run', 'search_chatrooms', 'search_friends', 'search_mps', 'send', 'send_file', 'send_image', 'send_msg', 'send_raw_msg', 'send_video', 'set_alias', 'set_chatroom_name', 'set_logging', 'set_pinned', 'show_mobile_login', 'start_receiving', 'storage', 'update_chatroom', 'update_friend', 'upload_file', 'utils', 'web_init']
help(itchat.login) #查看login函数使用方式
Help on method login in module itchat.components.login:
login(enableCmdQR=False, picDir=None, qrCallback=None, loginCallback=None, exitCallback=None) method of itchat.core.Core instance
'''
login为登录函数使用如下:
login后系统会弹出一张二维码
扫码后登录微信
'''
![QQ图片20181105233137.png](https://upload-images.jianshu.io/upload_images/14507859-926922e262879e75.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
itchat.login()
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
Login successfully as 小罗
# 信息获取
itchat.get_contact() #获取群聊信息与get_chatroom作用一样
<ContactList: []>
print(itchat.get_contact()) #输出群聊信息如下
[<Chatroom: {'ChatRoomId': 0, 'RemarkPYInitial': '', 'UserName': '@2572a640d0a9fdf08a2c80033d7463d810796fbfabddd114af3ea685dac23f6e', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '', 'VerifyFlag': 0, 'AttrStatus': 0, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'City': '', 'SnsFlag': 0, 'PYInitial': '', 'Sex': 0, 'PYQuanPin': '', 'ContactFlag': 0, 'HeadImgUrl': '', 'Signature': '', 'IsAdmin': None, 'Self': <User: {'ChatRoomId': 0, 'RemarkPYInitial': '', 'UserName': '@2572a640d0a9fdf08a2c80033d7463d810796fbfabddd114af3ea685dac23f6e', 'StarFriend': 0, 'UniFriend': 0, 'HeadImgFlag': 1, 'MemberCount': 0, 'OwnerUin': 0, 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 2298338667, 'MemberList': <ContactList: []>, 'NickName': '小罗', 'VerifyFlag': 0, 'AttrStatus': 0, 'WebWxPluginSwitch': 0, 'DisplayName': '', 'KeyWord': '', 'Alias': '', 'City': '', 'SnsFlag': 1, 'ContactFlag': 0, 'Sex': 1, 'PYQuanPin': '', 'Province': '', 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=323727957&username=@2572a640d0a9fdf08a2c80033d7463d810796fbfabddd114af3ea685dac23f6e&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'Signature': '', 'AppAccountFlag': 0, 'EncryChatRoomId': '', 'RemarkName': '', 'PYInitial': ''}>, 'AppAccountFlag': 0, 'RemarkName': '', 'Province': ''}>]
#获取好友信息
print(itchat.get_friends())
[<User: {'RemarkPYInitial': '', 'UserName': '@2572a640d0a9fdf08a2c80033d7463d810796fbfabddd114af3ea685dac23f6e', 'OwnerUin': 0, 'StarFriend': 0, 'UniFriend': 0, 'HeadImgFlag': 1, 'MemberCount': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=323727957&username=@2572a640d0a9fdf08a2c80033d7463d810796fbfabddd114af3ea685dac23f6e&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 2298338667, 'MemberList': <ContactList: []>, 'NickName': '小罗', 'VerifyFlag': 0, 'AttrStatus': 0, 'WebWxPluginSwitch': 0, 'DisplayName': '', 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'Province': '', 'Sex': 1, 'PYQuanPin': '', 'ContactFlag': 0, 'ChatRoomId': 0, 'Signature': '', 'AppAccountFlag': 0, 'EncryChatRoomId': '', 'City': '', 'PYInitial': ''}>, <User: {'RemarkPYInitial': '', 'UserName': '@91457010611eeaae3d70329fb2d818f284dfb89dac82ed3a082d204b5a252be0', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '杨强', 'VerifyFlag': 0, 'AttrStatus': 100583, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 1, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=682389274&username=@91457010611eeaae3d70329fb2d818f284dfb89dac82ed3a082d204b5a252be0&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'yangqiang', 'PYInitial': 'YQ', 'ChatRoomId': 0, 'Signature': '中', 'AppAccountFlag': 0, 'City': '', 'Province': '上海'}>, <User: {'RemarkPYInitial': '', 'UserName': '@d7f2e8e8ffcb63d21c6e6a4c9245a1a45eebba9361a98c9af35adcf8dcc31df2', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '太幹脆', 'VerifyFlag': 0, 'AttrStatus': 4193, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 2, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=645344618&username=@d7f2e8e8ffcb63d21c6e6a4c9245a1a45eebba9361a98c9af35adcf8dcc31df2&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'taigancui', 'PYInitial': 'TGC', 'ChatRoomId': 0, 'Signature': '现在要饭都难,要改行了,又不知道做什么?_?', 'AppAccountFlag': 0, 'City': '长沙', 'Province': '湖南'}>, <User: {'RemarkPYInitial': '', 'UserName': '@c44bc4c95ed75f0844d1407e33112db5fa64d30444cc7858f35465ec5d10c65b', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '攀登者', 'VerifyFlag': 0, 'AttrStatus': 103037, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 1, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=645345060&username=@c44bc4c95ed75f0844d1407e33112db5fa64d30444cc7858f35465ec5d10c65b&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'pandengzhe', 'PYInitial': 'PDZ', 'ChatRoomId': 0, 'Signature': '为道而生,为义而死。责任 法 理 情 仁 义', 'AppAccountFlag': 0, 'City': '大连', 'Province': '辽宁'}>, <User: {'RemarkPYInitial': '', 'UserName': '@b1b777ffa244b7b47a133dcf93230b68e1778c0216066799aa468a4dbb52f72a', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '赵志华', 'VerifyFlag': 0, 'AttrStatus': 4133, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 17, 'ContactFlag': 3, 'Sex': 1, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=645345539&username=@b1b777ffa244b7b47a133dcf93230b68e1778c0216066799aa468a4dbb52f72a&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'zhaozhihua', 'PYInitial': 'ZZH', 'ChatRoomId': 0, 'Signature': '', 'AppAccountFlag': 0, 'City': '益阳', 'Province': '湖南'}>, <User: {'RemarkPYInitial': '', 'UserName': '@eb9b5f6ea7c3b708b42ebf21f5b438b090e914cfc3aef911d4f3924ca651cd86', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '【丰凝国际】执行董事_殷慧敏', 'VerifyFlag': 0, 'AttrStatus': 135205, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=658830535&username=@eb9b5f6ea7c3b708b42ebf21f5b438b090e914cfc3aef911d4f3924ca651cd86&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'fengningguojizhixingdongshiyinhuimin', 'PYInitial': 'FNGJZXDSYHM', 'ChatRoomId': 0, 'Signature': '', 'AppAccountFlag': 0, 'City': '', 'Province': ''}>, <User: {'RemarkPYInitial': '', 'UserName': '@1de9e4494ae7675399fdfb44b493d249e9368e6a5d06619c509a21fb18a77904', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '大时贷', 'VerifyFlag': 0, 'AttrStatus': 102757, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=645353890&username=@1de9e4494ae7675399fdfb44b493d249e9368e6a5d06619c509a21fb18a77904&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'dashidai', 'PYInitial': 'DSD', 'ChatRoomId': 0, 'Signature': '微信不聊 直接添加工作QQ1361912045', 'AppAccountFlag': 0, 'City': '', 'Province': ''}>, <User: {'RemarkPYInitial': '', 'UserName': '@64023b45034dc0ebff3952cbe1d83c84c014f41d72f41e3e007242e184f93596', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '姚永良', 'VerifyFlag': 0, 'AttrStatus': 102881, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': 'yao', 'Alias': '', 'RemarkName': '', 'SnsFlag': 17, 'ContactFlag': 3, 'Sex': 1, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=660027821&username=@64023b45034dc0ebff3952cbe1d83c84c014f41d72f41e3e007242e184f93596&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'yaoyongliang', 'PYInitial': 'YYL', 'ChatRoomId': 0, 'Signature': '本人从事教练,有学车的朋友可以找我。', 'AppAccountFlag': 0, 'City': '益阳', 'Province': '湖南'}>, <User: {'RemarkPYInitial': '', 'UserName': '@1ca9a2ff7e2708721c0aeecbed63367ba816b1b7b12e3f162442378ba493cb3a', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '溜乎英语王老师77', 'VerifyFlag': 0, 'AttrStatus': 233473, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 0, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=660036843&username=@1ca9a2ff7e2708721c0aeecbed63367ba816b1b7b12e3f162442378ba493cb3a&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'liuhuyingyuwanglaoshi77', 'PYInitial': 'LHYYWLS77', 'ChatRoomId': 0, 'Signature': '', 'AppAccountFlag': 0, 'City': '', 'Province': ''}>, <User: {'RemarkPYInitial': '', 'UserName': '@84437956b98b31aed21335d9e5a51a43a29efe75f953044761265018d97e3f3a', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '湖南省交通医院 刘医生', 'VerifyFlag': 0, 'AttrStatus': 102497, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 2, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=660038263&username=@84437956b98b31aed21335d9e5a51a43a29efe75f953044761265018d97e3f3a&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'hunashengjiaotongyiyuanliuyisheng', 'PYInitial': 'HNSJTYYLYS', 'ChatRoomId': 0, 'Signature': '心理成长的路或许艰难坎坷,希望我能陪伴你感受成长和蜕变的滋味', 'AppAccountFlag': 0, 'City': '', 'Province': ''}>, <User: {'RemarkPYInitial': '', 'UserName': '@a68cfd8504ad26bd958d9d761ab0e841fc70e014253f6054a6282d282a60a4d0', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '李', 'VerifyFlag': 0, 'AttrStatus': 102437, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 2, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=660044769&username=@a68cfd8504ad26bd958d9d761ab0e841fc70e014253f6054a6282d282a60a4d0&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'li', 'PYInitial': 'L', 'ChatRoomId': 0, 'Signature': '', 'AppAccountFlag': 0, 'City': '', 'Province': ''}>, <User: {'RemarkPYInitial': '', 'UserName': '@15c775083589d73877fdd79fc4e454d05e7b04f67b2a9b37c3228ab56e6277ca', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, ''@b41fc50d631be278e73c19aa6a45e7cc5608729558cf0b4f34107d77359c47d4', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, bin/webwxgeticon?seq=660067765&username=@f83a3d411acd40da034d5f9aceb9c780eee0fd4ac1d224fc396365371a01eb64&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'renzhe', 'PYInitial': 'RZ', 'ChatRoomId': 0, 'Signature': '', 'AppAccountFlag': 0, 'City': '湘西', 'Province': '湖南'}>, <User: {'RemarkPYInitial': '', 'UserName': '@3812759bd552bd5ccb9ac2014dabe988a08caf997559c61cf9d967aa3957cbcf', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': 'sun', 'VerifyFlag': 0, 'AttrStatus': 233509, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 1, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=660070566&username=@3812759bd552bd5ccb9ac2014dabe988a08caf997559c61cf9d967aa3957cbcf&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'sun', 'PYInitial': 'SUN', 'ChatRoomId': 0, 'Signature': '下一个就是你', 'AppAccountFlag': 0, 'City': '', 'Province': ''}>, <User: {'RemarkPYInitial': '', 'UserName': '@9aec003b07f8bc1cb941750ec2339f45e006cd885e9903b90190e3a8c8607707', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '??', 'VerifyFlag': 0, 'AttrStatus': 135269, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 2, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?-bin/mmwebwx-bin/webwxgeticon?seq=645350631&username=@5a2caa870ca0fa1316fdd14dccb1edf3e5ccb9446fae9a36cc71c2ec8c4164fe&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'luoqiucaibajiu', 'PYInitial': 'LQCBJ', 'ChatRoomId': 0, 'Signature': '', 'AppAccountFlag': 0, 'City': '益阳', 'Province': '湖南'}>, <User: {'RemarkPYInitial': '', 'UserName': '@f375c950a620ec635c6532e21af6ed8c', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '何健--我爱小区装饰,德建建筑', 'VerifyFlag': 0, 'AttrStatus': 2084, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': 'woa', 'Alias': '', 'RemarkName': '', 'SnsFlag': 17, 'ContactFlag': 3, 'Sex': 1, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=660066804&username=@f375c950a620ec635c6532e21af6ed8c&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'hejianwoaixiaoouzhuangshidejianjianzhu', 'PYInitial': 'HJWAXOZSDJJZ', 'ChatRoomId': 0, 'Signature': '生命不息,奋斗不止!', 'AppAccountFlag': 0, 'City': '益阳', 'Province': '湖南'}>, <User: {'RemarkPYInitial': '', 'UserName': '@528e1ff63ab0b2be77c4554ad3ce7b4a8d33f56d541661a98d32e7627d9a1856', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '藤门国际 殷老师Yuki', 'VerifyFlag': 0, 'AttrStatus': 102437, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=660073383&username=@528e1ff63ab0b2be77c4554ad3ce7b4a8d33f56d541661a98d32e7627d9a1856&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'tengmenguojiyinlaoshiYuki', 'PYInitial': 'TMGJYLSYUKI', 'ChatRoomId': 0, 'Signature': '', 'AppAccountFlag': 0, 'City': '', 'Province': ''}>, <User: {'RemarkPYInitial': '', 'UserName': '@c1950f870fc12929c9129f07f05c7e706d03d655aa57f5e4d8eb91a1062da1d0', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '翔子', 'VerifyFlag': 0, 'AttrStatus': 4133, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 1, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=680576458&username=@c1950f870fc12929c9129f07f05c7e706d03d655aa57f5e4d8eb91a1062da1d0&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'xiangzi', 'PYInitial': 'XZ', 'ChatRoomId': 0, 'Signature': '', 'AppAccountFlag': 0, 'City': '益阳', 'Province': '湖南'}>, <User: {'RemarkPYInitial': '', 'UserName': '@04d1339c145286aacd49aaa5014f44d03a99ddc8fabf9176cd5d0f62b97b0a9e', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '支付宝授权服务商', 'VerifyFlag': 0, 'AttrStatus': 103101, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'RemarkName': '', 'SnsFlag': 1, 'ContactFlag': 3, 'Sex': 1, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=660078370&username=@04d1339c145286aacd49aaa5014f44d03a99ddc8fabf9176cd5d0f62b97b0a9e&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'zhifubaoshouquanfuwushang', 'PYInitial': 'ZFBSQFWS', 'ChatRoomId': 0, 'Signature': '一枚精致的猪猪男孩', 'AppAccountFlag': 0, 'City': '', 'Province': ''}>, <User: {'RemarkPYInitial': '', 'UserName': '@73d9603d74264634d65a6f258d4f216d8bff53cbd0f0ba1be25b08dea5a27ea8', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0,
#获取公众号
print(itchat.get_mps())
[<MassivePlatform: {'RemarkPYInitial': '', 'UserName': '@2d8e24529fffb8dee6f049fc8e92923b', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '酷玩实验室', 'VerifyFlag': 24, 'AttrStatus': 0, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': 'gh_', 'Alias': '', 'RemarkName': '', 'SnsFlag': 0, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=645344680&username=@2d8e24529fffb8dee6f049fc8e92923b&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'kuwanshiyanshi', 'PYInitial': 'KWSYS', 'ChatRoomId': 0, 'Signature': '一个说人话的科技频道', 'AppAccountFlag': 0, 'City': '朝阳', 'Province': '北京'}>, <MassivePlatform: {'RemarkPYInitial': '', 'UserName': '@9da6355b7864af21c2d23dfec552d8e7', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '数学与人工智能', 'VerifyFlag': 8, 'AttrStatus': 0, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': 'gh_', 'Alias': '', 'RemarkName': '', 'SnsFlag': 0, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=680577363&username=@9da6355b7864af21c2d23dfec552d8e7&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'shuxueyurengongzhineng', 'PYInitial': 'SXYRGZN', 'ChatRoomId': 0, 'Signature': '交流数学算法及人工智能方面的知识,传播令人匪夷所思的数学思想及算法!', 'AppAccountFlag': 0, 'City': '海淀', 'Province': '北京'}>, <MassivePlatform: {'RemarkPYInitial': '', 'UserName': '@f4151069d1654c6a6772bb59a0435d8c', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '人民日报', 'VerifyFlag': 24, 'AttrStatus': 0, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': 'gh_', 'Alias': '', 'RemarkName': '', 'SnsFlag': 0, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=680573654&username=@f4151069d1654c6a6772bb59a0435d8c&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'renminribao', 'PYInitial': 'RMRB', 'ChatRoomId': 0, 'Signature': '参与、沟通、记录时代。', 'AppAccountFlag': 0, 'City': '朝阳', 'Province': '北京'}>, <MassivePlatform: {'RemarkPYInitial': '', 'UserName': '@5b491e4d683a6a76d78af88e0f5c7dc8', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '中国建设银行', 'VerifyFlag': 24, 'AttrStatus': 0, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': 'gh_', 'Alias': '', 'RemarkName': '', 'SnsFlag': 0, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=645342784&username=@5b491e4d683a6a76d78af88e0f5c7dc8&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'zhongguojiansheyinxing', 'PYInitial': assivePlatform: {'RemarkPYInitial': '', 'UserName': '@673a921c7a29e8a3f2377c45cb3d1298', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': g', 'send_raw_msg', 'send_video', 'set_alias', 'set_chatroom_name', 'set_logging', 'set_pinned', 'show_mobile_login', 'start_receiving', 'storage', 'update_chatroom', 'update_friend', 'upload_file', 'utils', 'web_init']
help(itchat.login) #查看login函数使用方式
Help on method login in module itchat.components.login:
login(enableCmdQR=False, picDir=None, qrCallback=None, loginCallback=None, exitCallback=None) method of itchat.core.Core instance
'''
login为登录函数使用如下:
login后系统会弹出一张二维码
扫码后登录微信
'''
itchat.login()
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
Login successfully as 小罗
# 信息获取
itchat.get_contact() #获取群聊信息与get_chatroom作用一样
<ContactList: []>
print(itchat.get_contact()) #输出群聊信息如下
[<Chatroom: {'ChatRoomId': 0, 'RemarkPYInitial': '', 'UserName': '@2572a640d0a9fdf08a2c80033d7463d810796fbfabddd114af3ea685dac23f6e', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '', 'VerifyFlag': 0, 'AttrStatus': 0, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': '', 'Alias': '', 'City': '', 'SnsFlag': 0, 'PYInitial': '', 'Sex': 0, 'PYQuanPin': '', 'ContactFlag': 0, 'HeadImgUrl': '', 'Signature': '', 'IsAdmin': None, 'Self': <User: {'ChatRoomId': 0, 'RemarkPYInitial': '', 'UserName': seq=323727957&username=@2572a640d0a9fdf08a2c80033d7463d810796fbfabddd114af3ea685dac23f6e&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'Signature': '', 'AppAccountFlag': 0, 'EncryChatRoomId': '', 'RemarkName': '', 'PYInitial': ''}>, 'AppAccountFlag': 0, 'RemarkName': '', 'Province': ''}>]
#获取好友信息
print(itchat.get_friends())
[<User: {'RemarkPYInitial': '', 'UserName': '@2572a640d0a9fdf08a2c80033d7463d810796fbfabddd114af3ea685dac23f6e', 'OwnerUin': 0, 'StarFriend': 0, 'UniFriend': 0, 'HeadImgFlag': 1, 'MemberCount': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=682382347&username=@044667c533348e1f4dcef3e798b4f4483fb255e97e60f79cd7f961bf46036707&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'ping', 'PYInitial': 'P', 'ChatRoomId': 0, 'Signature': '本人电话改为15292086220,敬请惠存。', 'AppAccountFlag': 0, 'City': '', 'Province': ''}>, <User: {'RemarkPYInitial': '', 'UserName': 'AppAccountFlag': 0, 'City': '', 'Province': ''}>]
#获取公众号
print(itchat.get_mps())
[<MassivePlatform: {'RemarkPYInitial': '', 'UserName': '@2d8e24529fffb8dee6f049fc8e92923b', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, '-bin/webwxgeticon?seq=645345262&username=@6a837e102abed085f0f26ac6e03ffc33&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'chengzhixin', 'PYInitial': 'CZX', 'ChatRoomId': 0, 'Signature': '城院大学生心理健康协会公众号', 'AppAccountFlag': 0, 'City': '益阳', 'Province': '湖南'}>, <MassivePlatform: {'RemarkPYInitial': '', 'UserName': '@2c0f96f668955dacfbb2e632914e85d4', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '校园司令', 'VerifyFlag': 24, 'AttrStatus': 0, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': 'gh_', 'Alias': '', 'RemarkName': '', 'SnsFlag': 0, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=645345689&username=@2c0f96f668955dacfbb2e632914e85d4&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'jiaoyuansiling', 'PYInitial': 'JYSL', 'ChatRoomId': 0, 'Signature': '致力于为全国大学生提供校园有效信息整合、校园活动线上解决方案以及校园生活娱乐、校园论坛社交等服务的移动社区。主打校园红人内容,提供包括校园资讯、热点专题、红人直播、校园活动/投票等功能。', 'AppAccountFlag': 0, 'City': '闵行', 'Province': '上海'}>, <MassivePlatform: {'RemarkPYInitial': '', 'UserName': '@68e6898949cb745c0f1ac19cb62a9191', 'IsOwner': 0, 'StarFriend': 0, 'UniFriend': 0, 'MemberCount': 0, 'DisplayName': '', 'Statues': 0, 'RemarkPYQuanPin': '', 'HideInputBarFlag': 0, 'Uin': 0, 'MemberList': <ContactList: []>, 'NickName': '城院校园文明先锋队', 'VerifyFlag': 8, 'AttrStatus': 0, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': 'gh_', 'Alias': '', 'RemarkName': '', 'SnsFlag': 0, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?NickName': '人工智能学家', 'VerifyFlag': 24, 'AttrStatus': 0, 'EncryChatRoomId': '', 'OwnerUin': 0, 'KeyWord': 'gh_', 'Alias': '', 'RemarkName': '', 'SnsFlag': 0, 'ContactFlag': 3, 'Sex': 0, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=682388899&username=@ef21d561312ba5d3fab3a962052ee3be&skey=@crypt_cef2bb07_389117056298306162f3dd15893c519c', 'PYQuanPin': 'rengongzhinengxuejia', 'PYInitial': 'RGZNXJ', 'ChatRoomId': 0, 'Signature': '致力成为权威的人工智能科技媒体和前沿科技研究机构', 'AppAccountFlag': 0, 'City': '海淀', 'Province': '北京'}>]
#输出类型如下返回一个ContactList类类型
print(type(itchat.get_contact()))
print(type(itchat.get_chatrooms()))
print(type(itchat.get_friends()))
print(type(itchat.get_mps()))
<class 'itchat.storage.templates.ContactList'>
<class 'itchat.storage.templates.ContactList'>
<class 'itchat.storage.templates.ContactList'>
<class 'itchat.storage.templates.ContactList'>