【发布时间】:2012-06-30 07:55:37
【问题描述】:
我目前正在尝试解析 HTML 文档以检索其中的所有脚注;该文件包含数十个。我真的不知道用来提取我想要的所有内容的表达式。问题是,类(例如“calibre34”)在每个文档中都是随机的。查看脚注所在位置的唯一方法是搜索“隐藏”,然后它总是文本,并用 标记关闭。下面是 HTML 文档中脚注之一的示例,我想要的只是文本。有任何想法吗?谢谢大家!
<td class="calibre33">1.<span><a class="x-xref" href="javascript:void(0);">
[hide]</a></span></td>
<td class="calibre34">
Among the other factors on which the premium would be based are the
average size of the losses experienced, a margin for contingencies,
a loading to cover the insurer's expenses, a margin for profit or
addition to the insurer's surplus, and perhaps the investment
earnings the insurer could realize from the time the premiums are
collected until the losses must be paid.</td>
【问题讨论】:
-
用什么解析? I hope you don't mean Regex... 用你用来解析 HTML 的语言标记你的帖子,否则没人能帮助你。
-
您能找到
a类的x-ref标记并获取最近的td父级吗? -
使用
XDocument(XML to LINQ) 或XmlDocument(POCO) 来解析您的 HTML。这两个 XML 库都已包含在 .NET/C# 中,并且非常健壮。 -
没有 td 元素怎么办?他们一样吗?我的意思是,脚注,它总是在同一个 td 元素中吗?如果你想用java解析,你可以去jericho html parser
-
所有脚注都在 td 标签中,但许多其他内容也是如此。这些 HTML 文档非常庞大,其中包含大量内容和标签,它们写得非常糟糕,我的工作就是把脚注拿出来,我只是不想坐在那里复制粘贴它们 30 年。另外,谢谢SpikeX,我去看看。