《进击的虫师》斗鱼颜值小姐姐的1000种自拍

简介: 想成为优秀的斗鱼主播,首先得掌握优秀的自拍技能;这次写个有意思的, 爬取斗鱼小姐姐的自拍头像...效果图:001002003004005分析频道...

想成为优秀的斗鱼主播,首先得掌握优秀的自拍技能;这次写个有意思的, 爬取斗鱼小姐姐的自拍头像...

效果图:

001
002
003
004
005

分析频道

频道API

获取关键参数

分析参数

查看Json

请求API, 爬虫负责翻页,https://www.douyu.com/gapi/rkc/directory/2_201/1

脚本运行界面

脚本运行

源码():

4月13日10时更新: 可按照主播人气, 对图片进行排序, 并实现了图片去重

import requests
from lxml import etree
import json
import os
import time

def getResponse(url):
    headers = {
        # 设置用户代理头(为狼披上羊皮)
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36",
    }
    response = requests.get(url, headers = headers)
    return response

def getAllChannelMark(response):
    data_etree = etree.HTML(response.content)
    title_list = data_etree.xpath('//div[@class="leftnav-cate"]//li/a')
    title_mark_list = []
    for title in title_list:
        title_name = title.xpath('@title')
        title_mark = title.xpath('@data-rk')
        if title_name and title_mark:
            tmp_title = {"title_name": title_name, "title_mark": title_mark}
            title_mark_list.append(tmp_title)

    return title_mark_list

def getChanneTitleMark(title_mark_list):
    for index, title_mark in enumerate(title_mark_list):
        print("编号:",index,"=>",title_mark["title_name"], end="")
        if index%4 == 0:
            print()

    checkNumPass = True
    while checkNumPass:
        try:
            channelNum = int(input("请输入主题对应的编号(例如: 33):"))
            checkNumPass = False
        except:
            print("输入的编号格式有误")

    ChanneTitleMark = title_mark_list[channelNum]["title_mark"]
    return ChanneTitleMark

def checkNumFormat(message):
    canPass = False
    num = 0
    while not canPass:
        try:
            num = int(input(message))
            canPass = True
        except:
            print("输入的格式有误请重新输入!")
    return num


def getSourceJson(ChanneTitleMark):
    num = checkNumFormat("请输入需要爬取的主播图片数量(例如: 200):")
    # 用于生产url的变量
    url_index = 0
    # 设置去重列表
    name_list = []
    while num > 0:
        JsonUrl = "https://www.douyu.com/gapi/rkc/directory/"+str(ChanneTitleMark[0])+"/" + str(url_index)
        SourceJson = getResponse(JsonUrl).content
        # 获取多个主播的信息
        anchors = json.loads(SourceJson)["data"]["rl"]

        # # 计算本轮获取的主播数量
        # anchor_num = len(anchors)
        # # 计算出待获取的图片数量
        # last_num = num
        # num = num - anchor_num
        # # 如果本次信息过量,则截取部分json信息
        # if num <= 0:
        #     anchors = anchors[0:last_num]
        groupAnchorInfoList = []
        for anchor in anchors:
            tmp_anchor_info = {}
            # 主播照片
            tmp_anchor_info["anchor_img"] = anchor["rs1"]
            # 主播名
            tmp_anchor_info["anchor_name"] = anchor["nn"]
            # 直播房间id
            tmp_anchor_info["anchor_rid"] = anchor["rid"]
            # 主题
            tmp_anchor_info["anchor_rn"] = anchor["rn"]
            # 即时热度(人气)
            tmp_anchor_info["anchor_ol"] = str(anchor["ol"])
            # 将人气补齐到百万级别
            if len(str(anchor["ol"])) < 7:
                ol_tmp = "0000000" + str(anchor["ol"])
                tmp_anchor_info["anchor_ol"] = ol_tmp[-7:]

            # 频道名
            tmp_anchor_info["channelName"] = anchor["c2name"]

            # 如果已经存在此主播图片, 则不添加
            if tmp_anchor_info["anchor_name"] not in name_list:

                groupAnchorInfoList.append(tmp_anchor_info)
                name_list.append(tmp_anchor_info["anchor_name"])

        # 获取一页, 保存一次
        url_index += 1

        num = saveImage(groupAnchorInfoList, num)

def saveImage(groupAnchorInfoList, num):
    # 延迟0.2秒
    time.sleep(0.2)
    for AnchorInfo in groupAnchorInfoList:
        if num > 0:
            # 建立文件夹
            try:
                os.makedirs("./images/%s"%(AnchorInfo["channelName"]))
            except Exception as e:
                pass

            # 写入图片
            file_path = "./images/%s/%s"%(AnchorInfo["channelName"], AnchorInfo["anchor_ol"]+"_"+AnchorInfo["anchor_name"]+"_"+AnchorInfo["anchor_rn"]+".jpg")
            file_data = getResponse(AnchorInfo["anchor_img"]).content

            try:
                with open(file_path, "wb+") as f:

                    f.write(file_data)
                    print(">",file_path, "下载成功", "剩余", num, "张")
            except Exception as e:
                pass
        num = num - 1
    return num

def main():
    response = getResponse("https://www.douyu.com/directory/all")
    title_mark_list = getAllChannelMark(response)
    ChanneTitleMark = getChanneTitleMark(title_mark_list)
    getSourceJson(ChanneTitleMark)



if __name__ == '__main__':
    main()

由于分析获取了API, 所以爬虫效率很高, 斗鱼的"颜值"(第33个)频道大概有940个主播, 耗时1分钟全部爬完...

目录
相关文章
|
机器学习/深度学习 异构计算 Python
Bert-vits2最终版Bert-vits2-2.3云端训练和推理(Colab免费GPU算力平台)
对于深度学习初学者来说,JupyterNoteBook的脚本运行形式显然更加友好,依托Python语言的跨平台特性,JupyterNoteBook既可以在本地线下环境运行,也可以在线上服务器上运行。GoogleColab作为免费GPU算力平台的执牛耳者,更是让JupyterNoteBook的脚本运行形式如虎添翼。 本次我们利用Bert-vits2的最终版Bert-vits2-v2.3和JupyterNoteBook的脚本来复刻生化危机6的人气角色艾达王(ada wong)。
Bert-vits2最终版Bert-vits2-2.3云端训练和推理(Colab免费GPU算力平台)
|
12月前
|
人工智能 Cloud Native 关系型数据库
三项第一,阿里云连续4年领跑游戏云市场
国际数据公司(IDC)最新发布《中国游戏云市场跟踪》报告显示,2024年阿里云在游戏云基础设施(IaaS)+ 云解决方案(Cloud Solution)、云基础设施(IaaS)、云解决方案(Cloud Solution)三个市场均取得第一。这已经是阿里云连续4年稳居游戏云整体市场份额第一。
|
12月前
|
传感器 人工智能 搜索推荐
只靠一个头,能做出被“可爱攻击”的AI智能宠物吗?
本文探讨了AI实体化的一个具体方向——AI智能宠物,尤其是仅靠“一个头”设计的可行性与潜力。相比复杂的人形机器人,头部AI宠物成本更低、技术门槛更小,且能聚焦语言和表情交互,打造情感连接。文章分析了AI宠物的市场机遇,如满足孤独经济需求、成为消费电子新趋势,并指出“可爱”只是入场券,真正留住用户的在于深度交互体验。最后强调,精准洞察用户需求是关键,避免陷入“有趣但无用”的陷阱,为AI实体化找到切实可行的商业化路径。
447 0
|
人工智能 关系型数据库 分布式数据库
阿里云PolarDB重磅发布云原生与Data+AI新特性,打造智能时代数据引擎
阿里云PolarDB重磅发布云原生与Data+AI新特性,打造智能时代数据引擎
840 0
|
数据安全/隐私保护
[SWPUCTF 2021 新生赛]原来你也玩原神
[SWPUCTF 2021 新生赛]原来你也玩原神
793 0
|
JavaScript Java 测试技术
基于SpringBoot+Vue的原神游戏商城的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue的原神游戏商城的详细设计和实现(源码+lw+部署文档+讲解等)
264 0
【植物大战僵尸杂交版】致敬传奇游戏玩家——一个普通人的六年坚持
【植物大战僵尸杂交版】致敬传奇游戏玩家——一个普通人的六年坚持
|
数据采集 机器学习/深度学习 自然语言处理
本地训练,开箱可用,Bert-VITS2 V2.0.2版本本地基于现有数据集训练(原神刻晴)
按照固有思维方式,深度学习的训练环节应该在云端,毕竟本地硬件条件有限。但事实上,在语音识别和自然语言处理层面,即使相对较少的数据量也可以训练出高性能的模型,对于预算有限的同学们来说,也没必要花冤枉钱上“云端”了,本次我们来演示如何在本地训练Bert-VITS2 V2.0.2模型。
本地训练,开箱可用,Bert-VITS2 V2.0.2版本本地基于现有数据集训练(原神刻晴)
|
JSON API 数据安全/隐私保护
微信公众号启用了服务器配置如何自定义菜单?
微信公众号启用了服务器配置如何自定义菜单?
1297 0