吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1184|回复: 4
收起左侧

[其他原创] [Javascript] 爬取王者荣耀的全部英雄图片

[复制链接]
不羁de流年 发表于 2023-8-17 14:36
本帖最后由 不羁de流年 于 2023-8-17 14:52 编辑

看到这位兄弟发的【[Python 转载] 爬取王者荣耀的全部英雄图片】 https://www.52pojie.cn/thread-1822124-1-1.html
心血来潮写了个非python版本的

Snipaste_2023-08-17_14-31-08.png
Snipaste_2023-08-17_14-30-39.png
Snipaste_2023-08-17_14-30-50.png

修改匹配的条件就可以实现JS下载资源,适合界面中有大量同规格的图片,具体代码如下:
[JavaScript] 纯文本查看 复制代码
async function downloadImages(images) {
  const downloadPromises = [];

  for (const image of images) {
    const imgUrlStr = image.src;
    console.log("url:" + imgUrlStr);
    const response = await fetch(imgUrlStr);
    const blob = await response.blob();
    const a = document.createElement("a");
    const url = window.URL.createObjectURL(blob);
    const filename = imgUrlStr.substring(imgUrlStr.lastIndexOf("/") + 1);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
    downloadPromises.push(Promise.resolve());
  }

  await Promise.all(downloadPromises);
}

const images = document.querySelectorAll('img[src*="game.gtimg.cn/images/yxzj/img20"]');
downloadImages(images);




如果是LOL英雄列表,匹配规则就改为
[JavaScript] 纯文本查看 复制代码
const images = document.querySelectorAll('img[src*="game.gtimg.cn/images/lol/act/img/champion"]');

Snipaste_2023-08-17_14-51-11.png


大概是这些站点,其他站点试一试也行,只要有相同规格的图片
https://pvp.qq.com/web201605/herolist.shtml 【英雄介绍】
https://pvp.qq.com/web201605/item.shtml 【局内道具】
https://pvp.qq.com/web201605/summoner.shtml  【召唤师技能】
https://lol.qq.com/guides/newOpen.html?ADTAG=cooperation.glzx 【LOL英雄列表】

免费评分

参与人数 3吾爱币 +7 热心值 +3 收起 理由
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
『情』为你开 + 1 + 1 我很赞同!
Readmy + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

bohong65 发表于 2023-8-17 20:14
这思路挺好的,愿意分析就能方便很多
liugougou 发表于 2023-8-18 09:10
淑名のハ凛月 发表于 2023-8-27 21:15
izgnib 发表于 2023-8-28 18:12
感谢楼主分享,学习了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-6 02:34

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表