我有两个选项给你(我最喜欢第二个。)
1. http://home.ccil.org/~cowan/XML/tagsoup
instead of parsing well-formed or valid XML,
parses HTML as it is found in the wild:
poor, nasty and brutish, though quite often far from short.
TagSoup is designed for
people who have to process this stuff using
some semblance of a rational application
design. By providing a SAX interface,
it allows standard XML tools to be applied to even the
worst HTML. TagSoup also includes a command-line processor that reads
HTML files and can generate either clean HTML or well-formed XML
that is a close approximation to XHTML.
这是我们正在使用的工具。我提到了另一个工具,但我没有使用它。
2。 http://htmlcleaner.sourceforge.net/download.php
只需下载 jar 文件并解压缩即可。并像下面那样运行 jar 文件。
例如 -
我有以下内容的 Html 文件
<table>
<tr>
<td>Wrong Table
它给出如下所示的输出
C:\Users\Lasitha Benaragama\Downloads\htmlcleaner-2.8>java -jar htmlcleaner-2.8.
jar src=http://localhost/fun/test.html
Apr 24, 2014 12:23:10 PM org.htmlcleaner.audit.HtmlModificationListenerLogger fi
reHtmlError
INFO: fireHtmlError:RequiredParentMissing(true) at tr
Apr 24, 2014 12:23:10 PM org.htmlcleaner.audit.HtmlModificationListenerLogger fi
reHtmlError
INFO: fireHtmlError:UnclosedTag(true) at table
Apr 24, 2014 12:23:10 PM org.htmlcleaner.audit.HtmlModificationListenerLogger fi
reHtmlError
INFO: fireHtmlError:UnclosedTag(true) at tbody
Apr 24, 2014 12:23:10 PM org.htmlcleaner.audit.HtmlModificationListenerLogger fi
reHtmlError
INFO: fireHtmlError:UnclosedTag(true) at tr
Apr 24, 2014 12:23:10 PM org.htmlcleaner.audit.HtmlModificationListenerLogger fi
reHtmlError
INFO: fireHtmlError:UnclosedTag(true) at td
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head />
<body><table>
<tbody><tr>
<td>Wrong Table</td></tr></tbody></table></body></html>
我也测试了你的 html,
输出是
C:\Users\Lasitha Benaragama\Downloads\htmlcleaner-2.8>java -jar htmlcleaner-2.8.
jar src=http://localhost/fun/test.html
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head />
<body>
<p style="margin-top: 0"> dasa </p>
<input size="1" type="text" value="a" />
</body></html>
C:\Users\Lasitha Benaragama\Downloads\htmlcleaner-2.8>
谢谢。