微信機器人開發-微信登錄和獲取好友列表


首先需要安裝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()

運行結果如下

用手機微信掃一下二維碼

登錄成功

獲取好友列表的結果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM