【问题标题】:Values of <td></td> is not returned using HtmlUnit<td></td> 的值不使用 HtmlUnit 返回
【发布时间】:2012-06-26 14:11:12
【问题描述】:

我在网页中有一个表格结构,如下所示

在此我尝试使用如下 HtmlUnit 代码获取 tr 中的所有值。

<tr  class="odd" id="rawmeta-123">
       <td class="rowid">1</td>
       <td>Arun</td>
       <td class="date">2006-04-13</td>
       <td></td>
       <td class="date"></td>
       <td></td>
       <td></td>
     </tr>

List byXPath = page2.getByXPath("//tr[@class='odd']/td/text()");

它返回前三个和第五个 td 值。但是不返回另一个的值。(

<td></td>). How to get this value as null using HtmlUnit?

我非常感谢您的 cmets。

【问题讨论】:

  • 请问有人能回答这个问题吗?我被困在这...

标签: java javascript jquery html-parsing htmlunit


【解决方案1】:

你在寻找这样的东西吗?

HtmlTableRow tr = (HtmlTableRow) page.getByXPath("//tr[@class='odd']/");
for (HtmlTableCell td: tr.getCells() ) {
    if (td.getTextContent().isEmpty()) {
    // this is null
    }
}

【讨论】:

  • 感谢您的回复...但这不起作用。问题是上面的getbyxpath没有解析标签本身。
猜你喜欢
  • 2012-06-17
  • 1970-01-01
  • 2013-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-14
  • 2020-12-20
  • 2014-05-18
相关资源
最近更新 更多