4

我正在尝试使用 jTidy 从(现实世界)HTML 中提取数据。但 jTidy 不解析自定义标签。

<html>
  <body>
    <myCustomTag>some text</myCustomTag>
    <anotherCustom>more text</anotherCustom>
  </body>
</html>

我无法在自定义标签之间获取文本。我必须使用 jTidy,因为我将使用 xpath。

我尝试了 HTMLCleaner,但它不支持完整的 xpath 功能。

4

2 回答 2

4

您还可以使用 Java Properties 对象设置属性,例如:

import java.util.Properties;
Properties oProps = new Properties();
oProps.setProperty("new-blocklevel-tags", "header hgroup article footer nav");

Tidy tidy = new Tidy();
tidy.setConfigurationFromProps(oProps);

这应该可以让您不必创建和加载配置文件。

于 2013-09-09T08:14:44.530 回答
2

查看http://tidy.sourceforge.net/docs/quickref.html#new-blocklevel-tags

它的快速和肮脏是创建一个文件,我命名我的 jTidyTags 并调用:

Tidy tidy = new Tidy();
tidy.setConfigurationFromFile("jTidyTags");

之后它会抛出一个警告说它不符合 W3C 但谁在乎呢。这将让您解析文件。

jTidyTags 的一个例子是:

new-blocklevel-tags: myCustomTag anotherCustom

希望这可以帮助!

于 2012-03-16T20:41:22.507 回答