首先需要安裝itchat庫,可以pip install itchat安裝,也可以在pycharm里安裝
# -*- coding:utf-8 -*-
__author__ = "MuT6 Sch01aR"
import itchat
def get_friends():
friends = itchat.get_friends(update=True) #獲取微信好友列表,如果設置update=True將從服務器刷新列表
for i in friends:
print(i)
def main():
itchat.auto_login(hotReload=True) #登錄,會下載二維碼給手機掃描登錄,hotReload設置為True表示以后自動登錄
get_friends()
itchat.run() #讓itchat一直運行
if __name__ == "__main__":
main()
運行結果如下

用手機微信掃一下二維碼

登錄成功
獲取好友列表的結果

