品牌logo
parent
0af1f19ae2
commit
5188bab2af
@ -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
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue