下载百度图片 HTML解析

 

public void init(String url) throws Exception{
		Document doc = Jsoup.connect(url).get();
		getImage(doc);
	}
	
	public void getJPG(String str) throws Exception{
		Document doc = Jsoup.parse(str);
		Elements imgs = doc.getElementsByTag("img");
		int a=0;
		String base = "c:\\baidu\\";
		for(Element ele:imgs){
			a++;
			String fileName = ele.attr("original");
			if(fileName!=null && fileName.length()>0){
				System.out.println(fileName);
				download(fileName,base+a+".jpg");
			}
		}
	}

  download 然后保存到本地电脑的目录下边,

Jsoup小巧,一般的功能都可以满足,刚试了下,效果还行,也许网络的问题,还是有些标签抓取到;

 


下载百度图片 HTML解析_第1张图片
 

 

你可能感兴趣的:(html)