Wie vermeide ich HTML-Head-Tags in Jsoup? Parse
Mit Jsoup versuche ich den angegebenen HTML-Inhalt zu analysieren. Nach Jsoup.parse () hängt die HTML-Ausgabe das Tag html, head und body an die Eingabe an. Ich möchte diese einfach ignorieren.
Sample Input:
<p><b>This <i>is</i></b> <i>my sentence</i> of text.</p>
Java Code:
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class HTMLParse {
public static void main(String args[]) throws IOException {
try{
File input = new File("/ab.html");
String html = FileUtils.readFileToString(input, null);
Document doc = Jsoup.parseBodyFragment(html);
doc.outputSettings().prettyPrint(false);
System.out.println(doc.html());
}
catch(Exception e){
e.printStackTrace();
}
}
}
Aktuelle Ausgabe:
<html><head></head><body><p><b>This <i>is</i></b> <i>my sentence</i> of text.</p>
</body></html>
Erwartete Ausgabe
<p><b>This <i>is</i></b> <i>my sentence</i> of text.</p>
Bitte hilfe.