微信爬取自己的朋友头像

from wxpy import *
import PIL.Image as Image
import os
import sys

#完成好友头像的获取及下载

def get_image():
    curr_dir=os.getcwd()
    if not os.path.exists(curr_dir+"Image/"):
        os.mkdir(curr_dir+"Image/")
    #登陆微信并获取好友信息
    bot=Bot()
    friends=bot.friends(update=True)
    #存储微信好友头像并存储在Image目录中
    n=0
    for friend in friends:
        friend.get_avatar(curr_dir+"Image/"+str(n)+".jpg")
        n+=1
#用于制作生成照片墙
def to_Photo_wall():
    #定义生成微信好友头像的尺寸
    image=Image.new("RGB",(650,650))
    #定义初始图片的位置
    x=0
    y=0
    #获取下载头像的文件
    ls=os.listdir(os.getcwd()+"Image/")
    #遍历文件夹的图片
    for file_names in ls:
        try:
            img=Image.open(os.getcwd()+"Image/"+file_names)
        except IOError:
            continue
        else:
            #重新设置图片的大小
            img=img.resize((50,50),Image.ANTIALIAS)
            image.paste(img,(x*50,y*50))
            x+=1
            if x==13:
                x=0;
                y+=1
    img=image.save(os.getcwd()+"friends.jpg")
if __name__=='__main__':
    get_image()
    to_Photo_wall()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值