java Jsoup爬虫获取王者荣耀所有皮肤壁纸



import java.io.IOException;

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

import demo.DownloadPicFromURL;

public class JsoupDemo {
	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 = "d:/test/" + pfmclb + ".jpg";
			
					sd.downloadPicture(
							"https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/" + yxdm + "/" + yxdm
									+ "-bigskin-" + i + ".jpg",
							patha);
					i++;
				}
			}
		}
	}
}

 

 

下载文件代码

package demo;
 
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
 
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 (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值