Java爬取王者荣耀所有英雄皮肤

如果想要现成的可以下载楼主上传到csdn上的皮肤包
官网高清王者荣耀所有英雄皮肤
两个类:

DownloadPicFromURL

package com.luntek.reptile_king_honor_imgs;


import java.io.*;
import java.net.URL;


/**
 * @description:
 * @author: Czw
 * @create: 2020-09-19 11:15
 **/
public class DownloadPicFromURL {
    //链接url下载图片
    public void downloadPicture(String urlList, String path) {
        URL url = null;
        try {
            url = new URL(urlList);
            DataInputStream dataInputStream = new DataInputStream(url.openStream());

            FileOutputStream fileOutputStream = new FileOutputStream(new File(path));

            ByteArrayOutputStream output = new ByteArrayOutputStream();

            byte[] buffer = new byte[1024];
            int length;

            while ((length = dataInputStream.read(buffer)) > 0) {
                output.write(buffer, 0, length);
            }
            fileOutputStream.write(output.toByteArray());
            dataInputStream.close();
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

ReptileHonorOfKingImgs

package com.luntek.reptile_king_honor_imgs;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
/**
 * 爬取王者荣耀英雄皮肤
 *
 * @author: Czw
 * @create: 2020-09-19 11:06
 **/
public class ReptileHonorOfKingImgs {

    public static void main(String[] args) throws IOException {

        // https://pvp.qq.com/web201605/herodetail/106.shtml
        Document document=Jsoup.connect("https://pvp.qq.com/web201605/herolist.shtml")
                .userAgent("Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)")
                .get();
        Elements select = document.select("[class=herolist clearfix]");
        Elements select2 = select.select("li");
        for (Element element : select2) {
            int i = 1;
            String attr = element.select("a").attr("href");
            String text = element.select("a").text();
            //https://pvp.qq.com/web201605/herodetail/106.shtml
            //https://pvp.qq.com/web201605/herodetail/173.shtml
            System.out.println("进去的lianje:" + "https://pvp.qq.com/web201605/" + attr);
            // 进入英雄介绍
            Document document2=Jsoup.connect("https://pvp.qq.com/web201605/"+attr)
                    .userAgent("Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)")
                    .get();
            //https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/106/106-bigskin-1.jpg
            // https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/184/184-bigskin-2.jpg
            String attr2 = document2.select("[class = zk-con1 zk-con]").attr("style");
            String yxdmj = attr2;
            System.out.println(yxdmj);
            // 初始背景

            String substring = attr2.substring(16, attr2.length() - 11);

            // 获取英雄代码
            // adder.substring(69, adder.length() - 29);
            String yxdm = substring.substring(53, 56);

            DownloadPicFromURL sd = new DownloadPicFromURL();
            String path = "d:/test/" + text + ".jpg";
            sd.downloadPicture("https:" + substring, path);
            // 获取皮肤背景
            Elements con1 = document2.select("[class = con1-pic]");
            Elements showbox = con1.select("[class = pic-show-box]");
            Elements pf = showbox.select("[class= pic-pf]");
            Elements pful = pf.select("ul");
            for (Element pful2 : pful) {
                String pfmc = pful2.select("[class = pic-pf-list pic-pf-list3]").attr("data-imgname");

                String[] split = pfmc.split("\\|");
                int a = split.length;
                for (String pfmclb : split) {
                    System.out.println(pfmclb);
                    // game.gtimg.cn/images/yxzj/img201606/skin/hero-info/108/108-bigskin-1.jpg
                    // https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/106/106-bigskin-1.jpg
                    // https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/184/184-bigskin-2.jpg
                    if (i > a) {
                        break;
                    }
                    String patha = "C:\\Users\\Administrator\\Desktop\\honorImgs\\" + pfmclb + ".jpg";

                    sd.downloadPicture(
                            "https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/" + yxdm + "/" + yxdm
                                    + "-bigskin-" + i + ".jpg",
                            patha);
                    i++;
                }
            }
        }
    }

}


修改存储路径
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一米阳光zw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值