Pythonクローラーwxpyは、WeChatの友達のアバターとニックネームを取得します

from wxpy import *
import os


def weixin_file_path():
    avater_dir = os.path.join(os.getcwd(), 'weixin')
    if not os.path.exists(avater_dir):
        os.mkdir(avater_dir)
    return avater_dir


def save_wx_avater(avater_dir):
    bot = Bot(cache_path=False)
    friends = bot.friends(update=True)
    list_name = []
    for friend in friends:
        try:
            friend.get_avatar(os.path.join(avater_dir, f'{str(friend.name)}.jpg'))
            list_name.append(friend.name)
            print("好友昵称:%s" % friend.name)
        except Exception as e:
            print("数据错误",e)
            pass
    with open('微信好友昵称.txt', 'w+', encoding='utf-8')as f:
        for n in list_name:
            f.write("'" + n + "',\n")
        f.close()
        print("程序结束:")
    print(list_name)


if __name__ == '__main__':
    avatar_dir = weixin_file_path()
    save_wx_avater(avatar_dir)

結果と保存されたアバターを実行し、WeChatがWebバージョンにログインできることを確認します

おすすめ

転載: blog.csdn.net/weixin_43407092/article/details/108012363