0

我有这个网页来源:

<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。

也许有人对正则表达式有想法?分享它。

4

1 回答 1

3

使用 HtmlAgilityPack 获得所需的内容应该非常简单。假设您将文档加载到HtmlDocument名为的对象中doc

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"));
}
于 2012-10-21T21:29:19.477 回答