by Anonymous » 23 Feb 2025, 14:23
Mit JSOUP versuche ich, den angegebenen HTML -Inhalt zu analysieren. Nach jSOUP.PARSE () findet die HTML -Ausgabe HTML , head und body zum Eingang an. Ich möchte diese nur ignorieren.
Code: Select all
[b]This [i]is[/i][/b] [i]my sentence[/i] of text.
[b]< /code>
Java-Code: < /p>
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();
}
}
}
Tatsächliche Ausgabe:
Code: Select all
This [i]is[/i][/b] [i]my sentence[/i] of text.
[b]
Erwartete Ausgabe:
Code: Select all
This [i]is[/i][/b] [i]my sentence[/i] of text.
Wie kann ich JSOUP daran hindern, diese Tags hinzuzufügen?
Mit JSOUP versuche ich, den angegebenen HTML -Inhalt zu analysieren. Nach jSOUP.PARSE () findet die HTML -Ausgabe HTML , head und body zum Eingang an. Ich möchte diese nur ignorieren.[code]
[b]This [i]is[/i][/b] [i]my sentence[/i] of text.
[b]< /code>
Java-Code: < /p>
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();
}
}
}
[/code]
[b] Tatsächliche Ausgabe: [/b]
[code]This [i]is[/i][/b] [i]my sentence[/i] of text.
[b]
[/code]
[b] Erwartete Ausgabe: [/b]
[code]This [i]is[/i][/b] [i]my sentence[/i] of text.
[/code]
Wie kann ich JSOUP daran hindern, diese Tags hinzuzufügen?