天天看點

執行個體 | 20行Python代碼,擷取全部微信好友頭像

from wxpy import *
import os,sys

# 初始化機器人,掃碼登陸微信,适用于Windows系統
bot = Bot()
# # Linux系統,執行登陸請調用下面的這句
# bot = Bot(console_qr=2, cache_path="botoo.pkl"
# 擷取目前路徑資訊
image_dir = os.getcwd()+'\\' + "FriendImgs\\"
# 如果儲存頭像的FriendImgs目錄不存在就建立一個
if not os.path.exists(image_dir):
    os.mkdir(image_dir)
os.popen('explorer ' + image_dir)
my_friends = bot.friends(update=True)
# 擷取好友頭像資訊并存儲在FriendImgs目錄中
n = 0
for friend in my_friends:

    print(friend)
    image_name = image_dir + str(n) + '.jpg'
    friend.get_avatar(image_name)
    n = n + 1      

繼續閱讀