【问题标题】:How to get HTML tables using xpath in c?如何在 c 中使用 xpath 获取 HTML 表格?
【发布时间】:2010-10-15 11:19:08
【问题描述】:

我在我的 c 项目中使用 libxml2。 我想知道如何使用 xpath 获取 html 文件中的所有表。 示例代码可以解决问题。

我需要解析html表中的数据。

谢谢

编辑:

这是表格的一行:

<tr class="report-data-row-even">
    <td class="NormalTxt report-data-cell report-data-column-even">
        <nobr>0.0285</nobr>
    </td>
    <td class="NormalTxt report-data-cell report-data-column-odd">
        <nobr>&#1508;&#1512;&#1496;&#1504;&#1512;</nobr>
    </td>
    <td class="NormalTxt report-data-cell report-data-column-even">
        <nobr>SMS</nobr>
    </td>
    <td class="NormalTxt report-data-cell report-data-column-odd">
        <nobr>1</nobr>
    </td>
    <td class="NormalTxt report-data-cell report-data-column-even">
        <nobr>054-2570130</nobr>
    </td>
    <td class="NormalTxt report-data-cell report-data-column-odd">
        <nobr>00:14:09</nobr>
    </td>
    <td class="NormalTxt report-data-cell report-data-column-even">
        <nobr>27/09/2010</nobr>
    </td>
    > 
</tr>

我需要能够提取 &lt;nobr&gt; 标签内的数据。

【问题讨论】:

  • 老兄!一个简单的谷歌搜索会给你所有这些答案!

标签: html c xpath html-parsing libxml2


【解决方案1】:

XPath 将是简单的“//table”

【讨论】:

  • 如何迭代表的所有行并打印值?
  • 在表对象上您要求带有“//tr”的后代节点
【解决方案2】:

好吧,我需要更多信息。 HTML 看起来如何?你在提取什么样的数据?还有为什么是C?尽管在 C 中创建 DOM 速度很快,但之后的字符串操作需要一些努力。为什么不是 Python?无论如何,这是您可以尝试的 xpath。

//table[@class='table_class']

这会为您的 HTML 页面中的所有表提供类名为“table_class”的表。您可以将其更改为 HTML 的组织方式。

【讨论】:

    【解决方案3】:

    为此你需要使用回调方法,

    对于字符。

    (空)字符(Xmlchar*)

    查看 libxml 文档

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-19
      • 2015-04-03
      • 2011-04-20
      • 1970-01-01
      • 2018-08-27
      相关资源
      最近更新 更多