pom.xml
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.5</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
为了实现用java程序自动下载html的图片,用了jsoup 和httpclient写了个下载的,做个记录。
Document doc;
try {
doc = Jsoup.parse(input, "UTF-8");
for (String tag : tags) {
Elements elements = doc.getElementsByTag("img");
for (Element ele : elements) {
String httpUrl = ele.attr("src");
}
}
} catch (IOException e) {
e.printStackTrace();
}
DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(this.url);
HttpResponse response = defaultHttpClient.execute(request);
HttpEntity entity = response.getEntity();
byte[] buffer= EntityUtils.toByteArray(entity);;