Jsoup中的元素选择器

形同js里的selector选择器

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;

//select选择器
public class JsoupDemo5 {
    public static void main(String[] args) throws IOException {
        String path = JsoupDemo1.class.getClassLoader().getResource("student.xml").getPath();
        Document document = Jsoup.parse(new File(path),"utf-8");

        System.out.println(document.select("#mouse"));
        //获取name的文本
        Elements name = document.select("name");
        System.out.println(name.get(1).text());

        //选取number为0001的学生
        Elements select = document.select("student[number='0001']");
        System.out.println(select);
    }
}


posted @ 2021-05-05 22:20  code-G  阅读(267)  评论(0编辑  收藏  举报