package day02; import org.apache.commons.io.FileUtils; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.junit.Test; import java.io.File; import java.io.IOException; public class jianxizfc {// <!--jsoup解析工具所需依赖--> // <dependency> // <groupId>org.jsoup</groupId> // <artifactId>jsoup</artifactId> // <version>1.10.3</version> // </dependency> // // <dependency> // <groupId>junit</groupId> // <artifactId>junit</artifactId> // <version>4.12</version> // <scope>test</scope> // </dependency> // // <dependency> // <groupId>commons-io</groupId> // <artifactId>commons-io</artifactId> // <version>2.6</version> // </dependency> // // <dependency> // <groupId>org.apache.commons</groupId> // <artifactId>commons-lang3</artifactId> // <version>3.7</version> // </dependency> //@Testpublic void qidong() throws IOException {//使用工具类读取文件,获取字符串String s = FileUtils.readFileToString(new File("C:\\Users\\LX\\Desktop\\新建文本文档.txt"), "utf-8");//解析字符串Document doc = Jsoup.parse(s);//按照标签筛选需要的内容String title = doc.getElementsByTag("title").first().text();System.out.println(title); }@Testpublic void qidong1() throws IOException {//按照文件解析文件字符Document parse = Jsoup.parse(new File("C:\\Users\\LX\\Desktop\\新建文本文档.txt"), "utf-8");//解析字符串String title = parse.getElementsByTag( "title").first().text();//按照标签筛选需要的内容System.out.println(title);} }