2012-12-03 108 views
-2

可能重複:
RegEx match open tags except XHTML self-contained tags從HTML獲取值

我不是在正則表達式非常好。 所以這裏是我的問題:我如何獲得 <td><a href="">之間的所有鏈接?

<td><a href="link"> 
+0

[HTML敏捷性包] (http://htmlagilitypack.codeplex.com/) – Habib

+0

http://stackoverflow.com/a/1732454/932418 –

+0

這是更好的解決方案使用HtmlAgilityPack:http://htmlagilitypack.co deplex.com/ –

回答

1
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); 
doc.LoadHtml(@"<td><a href=""link"">"); 

var links = doc.DocumentNode.SelectNodes("//a[@href]") 
      .Select(a => a.Attributes["href"].Value) 
      .ToList(); 
2

使用HTML Agility Pack解析HTML文件:

一旦你正在使用的DLL可以獲取價值 使用代碼這樣的:

linkNode.Attributes["href"]