Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何读取在html之外写入的字符串<&燃气轮机;标签。?_Java_Html_String_File Io_Substring - Fatal编程技术网

Java 如何读取在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

我有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 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