1. Jsoup下载地址:
http://jsoup.org/packages/jsoup-1.8.1.jar
或者Maven Central
http://central.maven.org/maven2/org/jsoup/jsoup/1.8.1/jsoup-1.8.1.jar
2.实现源码
public classRun {
public static voidmain(String[] args)throwsCommonException,IOException{
String urlStr ="https://m.XXXXx.com";
// 将获取的网页 HTML 源代码转化为 Document
// Document doc = Jsoup.parse(htmlStr);
Document doc = Jsoup.connect(urlStr).get();
//head元素中内容
Element articleEle = doc.head();
//body元素中内容
Element contentEle = doc.body();
// 标题
String titleStr = articleEle.text();
System.out.println(titleStr);
Elements images = contentEle.getElementsByTag("img");
String[] imageUrls =newString[images.size()];
for(inti =0;i < imageUrls.length;i++) {
imageUrls[i] = images.get(i).attr("src");
System.out.println(imageUrls[i]);
}
}
}
3.运行结果
网友评论