python 爬虫 wxpy 获取微信好友的头像和昵称

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)

运行结果,和保存的头像,要确保微信能登录网页版哦

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值