安裝itchat
pip install itchat
使用
新建wxfx.py,拷貝以下代碼
# -*- coding: utf-8 -*-
#導入模塊
from wxpy import *
'''
微信機器人登錄有3種模式,
(1)極簡模式:robot = Bot()
(2)終端模式:robot = Bot(console_qr=True)
(3)緩存模式(可保持登錄狀態):robot = Bot(cache_path=True)
'''
#初始化機器人,選擇緩存模式(掃碼)登錄
robot = Bot(cache_path=True)
#獲取好友、羣、公衆號信息
robot.chats()
#獲取好友的統計信息
Friends = robot.friends()
print(Friends.stats_text())
運行
CMD->CD到wxfx.py所在目錄運行,然後掃碼登錄
結果
Author:TANKING
Wechat:likeyunba520
Web:http://likeyunba.com