爬取的是http://www.netbian.com网站的图片,要使用分类中的地址时只需要在网址后边加上"/地址":http://www.netbian.com/weimei/
保存地址E:\DeskTop\image\background
首先创建Maven工程
引入引入入依赖
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
完整代码块:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class ImgUtil02 {
private static String url = "http://www.netbian.com";
private static String urlll = "http://www.netbian.com";
public static void main(String[] args) {
upload(url);
}
public static void upload(String url) {
int s = 1;
String resouce = getResource(url);
HashMap src =(HashMap)getUrlFromCode(resouce);
Iterator itr=src.