diff --git a/src/main/java/cj/reptile/App.java b/src/main/java/cj/reptile/App.java index 7f85aa5..95e07ae 100644 --- a/src/main/java/cj/reptile/App.java +++ b/src/main/java/cj/reptile/App.java @@ -52,32 +52,20 @@ public class App { return filename; } - public static void main(String[] args) throws IOException, URISyntaxException { - /* - * String folderPath = "D:\\db"; File folder = new File(folderPath); - * - * if (!folder.exists()) { if (folder.mkdirs()) { - * System.out.println("文件夹创建成功!"); } else { System.out.println("文件夹创建失败!"); } } - * else { System.out.println("文件夹已存在!"); } - */ - - /* - * if(src != null) { InputStream inputStream = getFileInputStream("https:"+src); - * ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); int ch;while - * ((ch = inputStream.read()) != -1) { bytestream.write(ch); } String fileName = - * BaseInfoS.getFileName(bytestream.toByteArray(), - * src.substring(src.lastIndexOf("/") + 1)); // bytestream.toByteArray() - * inputStream.close(); bytestream.close(); - * System.out.println("fileName:"+fileName); brand.put("brand_logo", fileName); - * } - */ - + public static void main(String[] args){ + String letter = ""; for (int a = 0; a < 26; a++) { char chr = (char) ((int) 'A' + a); letter = chr + ""; Connection connect = Jsoup.connect("https://www.autohome.com.cn/grade/carhtml/" + letter + ".html"); - Document document = connect.get(); + Document document=null; + try { + document = connect.get(); + } catch (IOException e) { + // TODO Auto-generated catch block + continue; + } String sp = ""; Elements els = document.select("dl"); for (int i = 0; i < els.size(); i++) { @@ -102,26 +90,84 @@ public class App { File folder = new File(path); - - - // folder.mkdirs(); - // atk_5998 Connection href = Jsoup.connect("https:" + s.attr("href")); - Document documentt = href.get(); + Document documentt = null; + try { + documentt = href.get(); + } catch (IOException e1) { + // TODO Auto-generated catch block + continue; + } Elements ee = documentt.select(".pic-main a"); - String imgsrc = ee.select("img").attr("src"); -// Element ee = e.getElementById("atk_"+pp(s.attr("href"))); -// path += "\\"; - if (imgsrc != null && imgsrc.length() > 0) { - String url="https:" +imgsrc; - - String savePath=path; - String filename=pai+f; - folder.mkdirs(); - download(url,savePath,filename.hashCode()+".jpg"); + if(ee.attr("href")!=null&&ee.attr("href").length()>0){ + Connection hrefcx= Jsoup.connect("https:" + ee.attr("href")); + Document documentcx = null; + try { + documentcx = hrefcx.get(); + } catch (IOException e1) { + // TODO Auto-generated catch block + continue; + //e1.printStackTrace(); + } + Elements cxpage = documentcx.select("#vrlist li"); + if(cxpage.size()!=0) { + Element firstcx = cxpage.get(0); + String ff = firstcx.select("a").attr("href"); + if(ff!=null&&ff.length()>0) { + Connection hrefvr= Jsoup.connect(ff); + Document documentvr = null; + try { + documentvr = hrefvr.get(); + } catch (IOException e1) { + // TODO Auto-generated catch block + continue; + } + Element imgsli = documentvr.select("script").get(3); + if(imgsli.html()!=null&&imgsli.html().length()>0) { + String val=imgsli.html().split("\"Url\":\"")[1]; + + String arr = val.split(".png")[0]; + String imgurl="https://panovr.autoimg.cn/pano/"+arr+".png"; + String savePath=path; + String filename=pai+f; + folder.mkdirs(); + try { + download(imgurl,savePath,filename.hashCode()+".png"); + } catch (IOException e1) { + continue; + // TODO Auto-generated catch block + // e1.printStackTrace(); + } + System.out.println(imgurl); + } + + } + + } + + + }; - } + + + + +// String imgsrc = ee.select("img").attr("src"); +// if (imgsrc != null && imgsrc.length() > 0) { +// String url="https:" +imgsrc; +// +// String savePath=path; +// String filename=pai+f; +// folder.mkdirs(); +// try { +// download(url,savePath,filename.hashCode()+".jpg"); +// } catch (IOException e1) { +// // TODO Auto-generated catch block +// e1.printStackTrace(); +// } +// +// } //System.out.println(imgsrc); @@ -131,14 +177,14 @@ public class App { } public static void download(String urlString, String savePath, String filename) throws IOException { - System.out.println(urlString); - System.out.println(savePath+filename); +// System.out.println(urlString); +// System.out.println(savePath+filename); // 构造URL URL url = new URL(urlString); // 打开连接 URLConnection con = url.openConnection(); // 设置请求超时为20s - con.setConnectTimeout(20 * 1000); + con.setConnectTimeout(200 * 1000); // 文件路径不存在 则创建 File sf = new File(savePath); if (!sf.exists()) { diff --git a/target/classes/cj/reptile/App.class b/target/classes/cj/reptile/App.class index adf6b8c..3e00dbc 100644 Binary files a/target/classes/cj/reptile/App.class and b/target/classes/cj/reptile/App.class differ