-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst_jsoup.java
More file actions
35 lines (30 loc) · 1002 Bytes
/
first_jsoup.java
File metadata and controls
35 lines (30 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
/**
* Jsoup快速入门
*/
public class first_jsoup {
public static void main(String[] args) throws IOException{
//2.获取Document对象,根据xml文档获取
//2.1获取student.xml的path
String path = first_jsoup.class.getClassLoader().getResource("student.xml").getPath();
//2.2解析xml文档,加载文档进内存,获取dom树 ---> Document
Document document = Jsoup.parse(new File(path), "UTF-8");
//3.获取元素对象 Element
Elements elements = document.getElementsByTag("name");
System.out.println(elements.size());
//3.1获取第一个name的Element对象
Element element = elements.get(0);
//3.2获取数据
String name = element.text();
System.out.println(name);
}
}
/*
* 2
* cpu code
* */