如何在HTML AGILity包中的节点中获取innerText ...?

时间:2010-06-07 11:26:16

标签: c# html-agility-pack

<a> contents <strong>strong content</strong> </a>

我只想在<a><strong>

之间出现“内容”

1 个答案:

答案 0 :(得分:1)

您必须从<strong> -

中的字符串中移除<a>中的字符串
var testString = "<a> contents <strong>strong content</strong> </a>";
var doc = new HtmlDocument();
doc.LoadHtml(testString);
var strWithinAnchor = doc.DocumentNode.SelectSingleNode("/a").InnerText;
var strWithinStrong = doc.DocumentNode.SelectSingleNode("/a/strong").InnerText;
var resultString = strWithinAnchor.Replace(strWithinStrong, string.Empty);