【发布时间】:2021-04-12 03:57:47
【问题描述】:
我正在解析一个 html 片段,但不知道这是一个片段。 我使用 jsoup HTML 解析器。 例如:
String html = "<script>document.location = \"http://example.com/\";</script>";
Document document = Jsoup.parse(html);
System.out.println(document.html());
输出:
<html>
<head>
<script>document.location = "http://example.com/";</script>
</head>
<body></body>
</html>
问:有没有办法知道<html>、<head>和<body>标签是Jsoup添加的,不在原始html片段中?
更新:
我还尝试启用错误跟踪:
Parser parser = Parser.htmlParser();
parser.setTrackErrors(500);
Document document = parser.parseInput(html, "example.com");
ParseErrorList errors = parser.getErrors();
但我得到一个空的错误列表。
【问题讨论】:
标签: jsoup html-parsing html-parser