如何使用html敏捷包单独获取链接的标题和href值?

我试图下载一个包含这样的表的页面

 ....  .... 
Name link
name_of_the_movie
message
Download

我想从td class =“ttr_name”中提取name_of_the_movie并从td class =“td_dl”下载链接

这是我用于遍历表行的代码

 HtmlAgilityPack.HtmlDocument hDocument = new HtmlAgilityPack.HtmlDocument(); hDocument.LoadHtml(htmlSource); HtmlNode table = hDocument.DocumentNode.SelectSingleNode("//table"); foreach (var row in table.SelectNodes("//tr")) { HtmlNode nameNode = row.SelectSingleNode("td[0]"); HtmlNode linkNode = row.SelectSingleNode("td[1]"); } 

目前我不知道如何检查nameNode和linkNode并提取其中的数据

任何帮助,将不胜感激

问候

我现在无法测试它,但它应该是以下几行之一:

  string name= namenode.Element("a").Element("b").InnerText; string url= linknode.Element("a").GetAttributeValue("href","unknown"); 
 nameNode.Attributes["title"] linkNode.Attributes["href"] 

假设您正在获取正确的节点。

  public const string UrlExtractor = @"(?: href\s*=)(?:[\s""']*)(?!#|mailto|location.|javascript|.*css|.*this\.)(?.*?)(?:[\s>""'])"; public static Match GetMatchRegEx(string text) { return new Regex(UrlExtractor, RegexOptions.IgnoreCase).Match(text); } 

以下是如何提取所有Href Url的方法。 我正在我的一个项目中使用该正则表达式,您可以修改它以满足您的需求并重写它以匹配标题。 我想在批量匹配它们会更方便