【爬虫 3】送给所有粉丝的新年礼物–粉丝画像

人工智能46

【爬虫 3】送给所有粉丝的新年礼物–粉丝画像

人生总会有迷茫,会有不知道哪里错了,会有一种说不出的心情。这是一种美妙的感觉,但也可能会让人非常不舒服。在过去的一年里,我一直在想我能做什么,我能做什么,如果我没有工作会发生什么。我还剩下什么?

[En]

Life will always be confused, there will be do not know what is wrong, there will be a kind of unspeakable mood. It's a wonderful feeling, but it can be very uncomfortable. Over the past year, I have been thinking about what I can do, what I can do, and what will happen if I don't have a job. What do I have left?

今年,我的粉丝第一次突破5000,我很高兴,工作之后的乐趣,就是写写文章,写写代码。让更多的人能了解到编程的乐趣,也是一件不错的事情。

我的更新频率不是那么准时,也不是很频繁。同时,这也让我怀疑自己。我的文章是否有意义,我是否能帮助你。我的方向是什么?

[En]

The frequency of my updates is not that punctual, nor is it very frequent. At the same time, it also makes me doubt myself. Whether my writing is meaningful, whether I can help you. What is my direction?

然后就在这种不断的自我内耗中,感觉整个人越来越坏。

一次翻看短视频的机会,我被点醒了,那句话让 我印象深刻:成功,不成功,失败,不失败,你总是患得患失,太在意昨天,又太担心将来,昨天已经成为历史,将来是一个谜团,今天,是上天赐给我们的礼物,像珍惜礼物哪样珍惜今天。

是的,这么简单的道理,只有亲身经历,才能知道,即使是一些简单的道理,也还在不断循环,不如珍惜当下,活好每一天,面对这么多可爱的人和可爱的事。给生活增添一点乐趣。

[En]

Yes, such a simple truth, only through personal experience, can we know that even some simple truths are still in a constant cycle, so it is better to cherish the present, live every day, and face so many lovely people and lovely things. Add a little fun to life.

今天,我给了我的粉丝一张照片,这张照片是由所有粉丝的头像组成的。感谢您的关注,您让我拥有了创作的热情,在未来,我们也会在一起。

[En]

Today, I gave my fans a picture, which is made up of the avatars of all the fans. Thank you for your attention, you let me have the enthusiasm of creation, in the future, we will also be together.

【爬虫 3】送给所有粉丝的新年礼物–粉丝画像

第一步:获取粉丝列表头像

import requests
import os

def get_fs_img(page,id):
    """获取图片链接,名称"""
    headers = {
        'Accept':'application/json, text/plain, */*',
        'Accept-Encoding':'gzip, deflate, br',
        'Accept-Language':'zh-CN,zh;q=0.9',
        'Connection':'keep-alive',
        'Host':'blog.csdn.net',
        'Origin':'https://djyqxbc-python.blog.csdn.net',
        'Referer':'https://djyqxbc-python.blog.csdn.net/?type=sub&subType=fans',
        'sec-ch-ua':'" Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"',
        'sec-ch-ua-mobile':'?0',
        'sec-ch-ua-platform':'"Windows"',
        'Sec-Fetch-Dest':'empty',
        'Sec-Fetch-Mode':'cors',
        'Sec-Fetch-Site':'same-site',
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
    }
    reponses=requests.get("https://blog.csdn.net/community/home-api/v2/get-fans-list?page="+str(page)+"&pageSize=500&id="+str(id)+"&noMore=false&blogUsername=qq_39046854",headers=headers)
    fs_list=reponses.json()["data"]["list"]
    for n,i in enumerate(fs_list):
        with open("photos\\"+i["username"]+".jpg","wb") as f:
            he={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'}
            img=requests.get(url=i["userAvatar"],headers=he).content
            f.write(img)
        if n==499:
            print(i["id"],page+1)
            page+=1
            get_fs_img(page,i["id"])

【爬虫 3】送给所有粉丝的新年礼物–粉丝画像

第二步:清除默认头像数据

数据中有一部分采用默认图像,因此需要去除默认图

【爬虫 3】送给所有粉丝的新年礼物–粉丝画像

def clear_default_img():
    """过滤默认头像"""
    for root, dirs, files in os.walk("photos"):
        for i in files:
            img_path="photos\\"+i
            f=open(img_path,"rb")
            b = f.read()
            for file in ["1.jpg","2.jpg","3.jpg","4.jpg"]:#比对默认图片,进行删除
                m = open(file, "rb")
                a=m.read()
                if a==b:
                    f.close()
                    os.remove(img_path)

第三步:生成粉丝图像

from PIL import Image
import numpy
import os
import random
import numexpr

# line_num: 一行放多少张照片
# # col_num: 一列放多少张照片
# # fans_w: 照片宽为多少
# # fans_h: 照片高为多少

line_num =100#一行放多少张照片
col_num = 100#一列放多少张照片
fans_w = 20#照片宽为多少
fans_h = 20#照片高为多少

def uniform_size(file_path, width, height):
    """将照片统一大小"""
    img = Image.open(file_path)
    if img.mode != "RGBA":img = img.convert("RGBA")
    uniform_img = img.resize((width, height))
    return numpy.array(uniform_img)[:height, :width]#创建一个数组。

def create_img():
    """创造图片,并保存"""
    list_img=[]
    path ="photos/"
    for i in os.listdir(path):
        list_img.append(path + i)
    wight = line_num * fans_w
    height = col_num * fans_h
    expr= numpy.array(uniform_size("icon.jpg", wight, height))#创建一个矩阵,二维数组。
    expr = numexpr.evaluate("expr*0.3")#加快运算速度
    for i in range(line_num):
        for j in range(col_num):
            ex = expr[(j * fans_h):((j + 1) * fans_h), (i * fans_w):((i + 1) * fans_w)]
            un = uniform_size(random.choice(list_img), fans_w, fans_h)#随机获得一张图片,并控制大小
            res = numexpr.evaluate("ex+un*0.7")#加快运算速度
            expr[(j * fans_h):((j + 1) * fans_h), (i * fans_w):((i + 1) * fans_w)] = res
    Image.fromarray(expr.astype(numpy.uint8)).save("fans_logo.png")

if __name__ == "__main__":
    create_img()

Original: https://blog.csdn.net/qq_39046854/article/details/122461820
Author: 大家一起学编程(python)
Title: 【爬虫 3】送给所有粉丝的新年礼物--粉丝画像

相关文章
如何进行模型的部署和优化 人工智能

如何进行模型的部署和优化

你好,这篇文章咱们讨论一下关于「如何进行模型的部署和优化」的事情... 模型部署和优化 在机器学习领域中,模型部署和优化是非常重要的。部署是指将机器学习模型应用于实际生产环境,而优化是指通过参数调整等...
文件夹(?)[+] 人工智能

文件夹(?)[+]

本文以某公司iPhone 6手机预约接口开发为例,介绍PHP5下SOAP调用的实现过程。 一、基础概念 SOAP(Simple Object Access Protocol )简单对象訪问协议是在分散...
离线语音风扇设计应用案例 人工智能

离线语音风扇设计应用案例

1 概述 ¶ 随着人们生活水平的提高,对产品的功能要求也越来越高,追求舒适的体验感,特别是对操控性的要求越来越高。目前风扇产品的控制方式有以下几类: 按键控制:传统控制方式,每次要走到风扇边才行,操作...
树莓派首次开机远程配置网络 人工智能

树莓派首次开机远程配置网络

最近刚买了树莓派,兴奋得到手立马拆封通电。冷静下来才发现手头连显示器键盘都没有,就算通过MobaXterm远程配置那也先组建局域网。还好手上有一台Windows笔记本,就边折腾边记录下组建局域网的过程...