【问题标题】:JSoup to extract particular block from multiple blockJSoup 从多个块中提取特定块
【发布时间】:2013-10-22 12:15:24
【问题描述】:

我是 JSoup 新手,我的问题是如何从共享相同类和属性的多个块中提取特定文本?

例如,在这里我想提取 HTML 第 3 行的信息。如何在我的 JSoup 代码中指定提取第三行的信息?

            <tr>
                <td align="center" colspan="2" class="maintitle">Active Stats</td>
            </tr>

            <tr>
                <td class="row2" valign="top"><b>User's local time</b></td>
                <td class="row1">Oct 22 2013, 07:23 PM</td>
            </tr>

            <tr>
                <td class="row2" width="30%" valign="top"><b>Total Cumulative Posts</b></td>
                <td width="70%" class="row1"><b>4</b>
                <br />( 0 posts per day / 0.00% of total forum posts )
                </td>
            </tr>

【问题讨论】:

    标签: html-parsing jsoup


    【解决方案1】:

    使用 CSS 选择器语法来指定要选择的行。

    Element e = doc.select("tr:eq(2) td.row2").first();
    System.out.println(e.text());
    

    会导致

    累计帖子总数

    提示是在提问之前至少查看 Jsoup 文档。 所有这些都可以在 API 中轻松找到。

    Jsoup - Use selector syntax

    【讨论】:

      猜你喜欢
      • 2020-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 2021-02-25
      • 2013-02-16
      • 2023-03-09
      相关资源
      最近更新 更多