借助qq空间拿好友qq号,下载头像,做成照片墙

  1. 首先可以通过电脑登陆qq,浏览器进入空间
    在这里插入图片描述
  2. 点击进入空间
    在这里插入图片描述
  3. 按f12进入开发者模式,默认在network,不用变,点一下2处清理干净,点一下3(好友),右侧会刷新出好多链接
    在这里插入图片描述
  4. 上下拖动,找到2的链接,如果看不到后缀的cgi,可以向右拖动1处的竖线多显示一些,点击friend_ship_manager.cgi
    在这里插入图片描述
  5. 点击response, ctrl+a全选,ctrl+c复制在这里插入图片描述
  6. 在电脑桌面或其他地方新建一个txt文档,将复制的文本粘贴进去保存,名字英文自取
  7. 下面是利用保存的txt进行拿出好友的qq号,并进行下载头像,拼接成照片墙``
import json
import re
import requests
import os
import time
import math
from PIL import Image
#头像存放文件夹
avatar_dir = os.getcwd() + "\\qqImgs\\"
if not os.path.exists(avatar_dir):
    os.mkdir(avatar_dir)

with open('friends_qq.txt','r',encoding='utf-8') as f:
    txt = f.read()
friend_json = re.findall('\((.*)\)',txt,re.S)[0]
# print(friend_json)
friend_dict = json.loads(friend_json)
# print(friend_dict)
friend_info_list = []
for friend in friend_dict['data']['items_list']:
    name = friend['name']
    qq = friend['uin']
    #获得头像地址
    friend_info_list.append([name,qq])

header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36",
}
for i in friend_info_list:
    avatar_url ='http://q.qlogo.cn/g?b=qq&nk=%s&s=640&mType=friendlist'%i[1]
    #下载头像
    response = requests.get(url=avatar_url,headers=header)
    img = response.content
    file = avatar_dir + str(i[1])
    with open('%s.jpg'%file,'wb') as f2:
        f2.write(img)
        print('%s下载成功'%i[1])
    time.sleep(1.5)

#拼接图像
def joint_avatar(path):
    # 获取文件夹内头像个数
    length = len(os.listdir(path))
    # 设置画布大小
    image_size = 2560
    # 设置每个头像大小
    each_size = math.ceil(2560 / math.floor(math.sqrt(length)))
    # 计算所需各行列的头像数量
    x_lines = math.ceil(math.sqrt(length))
    y_lines = math.ceil(math.sqrt(length))
    image = Image.new('RGB', (each_size * x_lines, each_size * y_lines))
    x = 0
    y = 0
    for (root, dirs, files) in os.walk(path):
        for pic_name in files:
            # 增加头像读取不出来的异常处理
                try:
                    with Image.open(path + pic_name) as img:
                        img = img.resize((each_size, each_size))
                        image.paste(img, (x * each_size, y * each_size))
                        x += 1
                        if x == x_lines:
                            x = 0
                            y += 1
                except IOError:
                    print("头像读取失败")

    img = image.save(os.getcwd() + "/qqFriends.png")
    print('qq好友头像拼接完成!')

joint_avatar(avatar_dir)
f.close()
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值