如果想要现成的可以下载楼主上传到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++;
}
}
}
}
}
修改存储路径