<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
Jsoup 可以简单爬取页面dom 获取数据
//找到要爬取页面
Document document = Jsoup.connect("http://www.baidu.com").get();
//获取标题
String title = document.title();
//获取html中的head
System.out.println(document.head());
//获取html中的body
Element body = document.body();
//获取body子标签
Elements children = body.children();
//获取标签名
String tagName = element.tagName();
//获取body class为xxx 的Element
Element element = parse.body().getElementsByClass("class").get(0);
//递归遍历子节点
public static void getDom(Element element){
//获取改节点子节点
Elements children = element.children();
for (int i = 0 ; i < children.size() ; i++){
//获取该节点数据
Element childrenElement = children.get(i);
System.out.println(childrenElement);
getDom(childrenElement,Xpath,Text);
}
}