diff --git a/.classpath b/.classpath index a460cc8..d94d5c6 100644 --- a/.classpath +++ b/.classpath @@ -27,6 +27,19 @@ + + + + + + + + + + + + + diff --git a/.project b/.project index 0e706b6..e4c7b98 100644 --- a/.project +++ b/.project @@ -20,4 +20,15 @@ org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + + + 1701761340333 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index ac8e750..1b6e1ef 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,9 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.processAnnotations=disabled org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/main/java/cj/reptile/Brand.java b/src/main/java/cj/reptile/Brand.java new file mode 100644 index 0000000..5fadc75 --- /dev/null +++ b/src/main/java/cj/reptile/Brand.java @@ -0,0 +1,85 @@ +package cj.reptile; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.net.URLConnection; + +import org.jsoup.Connection; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +public class Brand { + public static String urlName(String filename) { + filename = filename.replaceAll(":", ""); + filename = filename.replaceAll("\\*", ""); + filename = filename.replaceAll("\\?", ""); + filename = filename.replaceAll("<", ""); + filename = filename.replaceAll(">", ""); + filename = filename.replaceAll("|", ""); + return filename; + } + public static void download(String urlString, String savePath, String filename) throws IOException { +// System.out.println(urlString); +// System.out.println(savePath+filename); + // 构造URL + URL url = new URL(urlString); + // 打开连接 + URLConnection con = url.openConnection(); + // 设置请求超时为20s + con.setConnectTimeout(200 * 1000); + // 文件路径不存在 则创建 + File sf = new File(savePath); + if (!sf.exists()) { + sf.mkdirs(); + } + InputStream in = con.getInputStream(); + OutputStream out = new FileOutputStream(sf.getPath() + "\\" + filename); + // 创建缓冲区 + byte[] buff = new byte[1024]; + int n; + // 开始读取 + while ((n = in.read(buff)) >= 0) { + out.write(buff, 0, n); + } + + } + + public static void main(String[] args) throws IOException { + 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(); + + Elements els = document.select("dl"); + for (int i = 0; i < els.size(); i++) { + Element e = els.get(i); + String src = e.select("dt a img").attr("src"); + String imgurl = "https:" + src; + System.out.println(imgurl); + String pai = e.select("dt div a").text(); + String path = "D:\\blogo\\" + pai; + File folder = new File(imgurl); + + String name = pai; + Long id = (long) name.hashCode(); + id += Integer.MAX_VALUE; + + + String newName = id+".png"; + folder.mkdirs(); + download(imgurl,path,newName); + + } + } + + } +} diff --git a/target/classes/META-INF/maven/cj/cj-reptile/pom.properties b/target/classes/META-INF/maven/cj/cj-reptile/pom.properties index fced898..999be17 100644 --- a/target/classes/META-INF/maven/cj/cj-reptile/pom.properties +++ b/target/classes/META-INF/maven/cj/cj-reptile/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Wed Nov 29 14:44:11 CST 2023 +#Tue Jan 02 16:45:53 CST 2024 m2e.projectLocation=D\:\\code\\reptile m2e.projectName=cj-reptile groupId=cj diff --git a/target/classes/cj/reptile/App.class b/target/classes/cj/reptile/App.class index 3e00dbc..2c08889 100644 Binary files a/target/classes/cj/reptile/App.class and b/target/classes/cj/reptile/App.class differ diff --git a/target/classes/cj/reptile/Brand.class b/target/classes/cj/reptile/Brand.class new file mode 100644 index 0000000..55eb64a Binary files /dev/null and b/target/classes/cj/reptile/Brand.class differ diff --git a/target/test-classes/cj/reptile/AppTest.class b/target/test-classes/cj/reptile/AppTest.class index 6589b69..d51e026 100644 Binary files a/target/test-classes/cj/reptile/AppTest.class and b/target/test-classes/cj/reptile/AppTest.class differ