Java 如何读取在html之外写入的字符串<&燃气轮机;标签。?
我有1000行的HTML代码,我想提取写在HTML标记之外的数据 例如Java 如何读取在html之外写入的字符串<&燃气轮机;标签。?,java,html,string,file-io,substring,Java,Html,String,File Io,Substring,我有1000行的HTML代码,我想提取写在HTML标记之外的数据 例如 <>Java Programm<> 您需要一个HTML解析器。对于JSoup来说,它是 File input = new File("C:\\Users\\File.txt"); Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/"); Element body = doc.body(); //Get the body
<>Java Programm<>
您需要一个HTML解析器。对于JSoup来说,它是
File input = new File("C:\\Users\\File.txt");
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
Element body = doc.body(); //Get the body of the html
System.out.println(body.text()) ; //Get the all the text inside the body tag
这是一种方法。很简单:),当然还有其他方法。这当然会将文本保留在body标记之外。您可以浏览JSoup并找到它的解决方案。好的,您正在阅读文本文件。你到底想解决什么问题(忽略标签)?@Adriano:OP没有尝试任何东西,他只是发布了这个问题。只需复制文件读取代码,并为我们进一步..提示:将其读取为XML(google读取java中的XML)。使用element.getTextContent获取标记之外的数据…@Hirak我没有获取。。
File input = new File("C:\\Users\\File.txt");
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
Element body = doc.body(); //Get the body of the html
System.out.println(body.text()) ; //Get the all the text inside the body tag