2012-11-20 34 views
0

我正在C#.net中製作一個項目,其中我必須獲取網頁的源代碼並識別一些特定的標籤。使用字符串如何獲取圖像標籤在C#中的HTML?

例如,我必須找到所有在代碼中

  <img> 

標籤。我必須將它存儲在一個變量中。

我成功地通過我的c#.net應用程序獲取網頁源代碼的第一步。 我不知道如何獲得一個標籤並將其位置存儲在一個變量中?

給我一個sugesstion

回答

0

我建議使用HtmlAgitityPack進行這項工作,它使用原始html標記非常靈活,可以獲得帶標記的內容。 :

HtmlDocument htmlDocument = new HtmlDocument(); 
htmlDocument.LoadHtml("<html><head></head><body><div><img /><div><img /><img/></div></div><img/></body></html>"); 

var nodes = htmlDocument.DocumentNode.SelectNodes("//img"); 
// 4 nodes found 
foreach (var node in nodes) 
{ 
    // do stuff 
} 
相關問題