HTMLAgilityPack链接和描述提取

时间:2010-07-30 14:07:24

标签: c# html-agility-pack

我有以下代码

foreach (HtmlNode link in htmldocObject.DocumentNode.SelectNodes("//a[@href]")) 
{ 
    HtmlAttribute attrib = link.Attributes["href"]; hTags.Add(att.Value);
}

这完全拉动了Href,但我也想拉出href的描述

示例

<a href="/users/logout?returnurl=%2fquestions%2fask">log out</a>

所以我已经获得了/users/logout?returnurl=%2fquestions%2fask但我还想获得log out

结果:

/users/logout?returnurl=%2fquestions%2fask | log out

1 个答案:

答案 0 :(得分:4)

你想要的东西:

hTags.Add(att.Value + " | " + link.InnerText);