如何从没有结束标记的节点获取innertext?

时间:2013-12-02 21:42:49

标签: xpath html-parsing html-agility-pack

我有以下节点:

  <option value="trz4.htm">TextIwant1
  <option value="trz5.htm">TextIwant2
  <option value="trz6.htm">TextIwant3
  <option value="trz2.htm">TextIwant4

HtmlAgilityPack没有将“TextIWant1 ...”作为innerText。我只得到空字符串:

private static List<string> GetTextIWant(IEnumerable<HtmlNode> nodes)
    {
        return nodes.Select(node => node.InnerText)).ToList();
    }

如何获得“TextIwant1 ..”?

1 个答案:

答案 0 :(得分:0)

我已经解决了。我认为“TextIwant”属于选项节点,但它实际上是下一个节点。

private static List<string> GetTextIWant(IEnumerable<HtmlNode> nodes)
{
    return nodes.Select(node => node.NextSibling.InnerHtml)).ToList();
}