2012-10-21 16 views
0

我有這個網頁源:提取從htmlagilitypack網頁全部`href`s /請求任何

<a href="/StefaniStoikova"><img alt="" class="head" id="face_6306494" src="http://img0.ask.fm/assets/054/771/271/thumb_tiny/sam_7082.jpg" /></a> 
<a href="/devos"><img alt="" class="head" id="face_18603180" src="http://img7.ask.fm/assets/043/424/871/thumb_tiny/devos.jpg" /></a> 
<a href="/frenop"><img alt="" class="head" id="face_4953081" src="http://img1.ask.fm/assets/029/163/760/thumb_tiny/dsci0744.jpg" /></a> 

我想<a href-"後立即提取字符串。但我的主要問題是這些字符串是不同的,我似乎沒有找到辦法。沒有agilitypack或webrequests。

也許有人有關於正則表達式的想法?分享它。

+0

要提取了'href'財產或整條生產線?如果你想在客戶端使用它,使用jquery很容易。 – manman

回答

3

通過HtmlAgilityPack獲得您需要的內容應該非常簡單。假設你有你的文件加載到一個名爲doc一個HtmlDocument對象:

HtmlNodeCollection collection = doc.DocumentNode.SelectNodes("//a[@href]"); 

foreach (HtmlNode node in collection) 
{ 
    // Do what you want with the href value in here. As an example, this just 
    // just prints the value to the console. 
    Console.WriteLine(node.GetAttributeValue("href", "default")); 
}