C# 使用字符串中的标记遍历HTML

C# 使用字符串中的标记遍历HTML,c#,php,html,foreach,getelementsbytagname,C#,Php,Html,Foreach,Getelementsbytagname,由于性能原因,我正在将一个PHP脚本解析为C 这是我遇到问题的PHP源代码: $dom = new DOMDocument; $dom->loadHTML($message); foreach ($dom->getElementsByTagName('a') as $node) { if ($node->hasAttribute('href')) { $link = $node->getAttribute('href'); if (

由于性能原因,我正在将一个PHP脚本解析为C

这是我遇到问题的PHP源代码:

$dom = new DOMDocument;
$dom->loadHTML($message);
foreach ($dom->getElementsByTagName('a') as $node) {
    if ($node->hasAttribute('href')) {
        $link = $node->getAttribute('href');
        if ((strpos($link, 'http://') === 0) || (strpos($link, 'https://') === 0)) {
            $add_key = ((strpos($link, '{key}') !== false) || (strpos($link, '%7Bkey%7D') !== false));
            $node->setAttribute('href', $url . 'index.php?route=ne/track/click&link=' . urlencode(base64_encode($link)) . '&uid={uid}&language=' . $data['language_code'] . ($add_key ? '&key={key}' : ''));
        }
    }
}
我遇到的问题是
getElementByTagName
部分

如前所述,我应该使用。到目前为止,我的代码是:

var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(leMessage);
leMessage
是一个包含HTML的字符串。到现在为止,一直都还不错。唯一的问题是HtmlAgillityPack中没有
getElementsByTag
函数。在正常的HtmlDocument(没有包)中,我不能使用字符串作为html页面,对吗


有人知道我该怎么做才能让这一切顺利吗?我现在唯一能想到的就是在windows窗体中创建一个webbrowser,并将文档内容设置为
leMessage
,然后从那里解析它。但就个人而言,我不喜欢那种解决方案。。。但是,如果没有其他方法…

以下是我跟随您的链接并单击“示例”时弹出的页面代码块的第一个顶部:


以后请自己用谷歌搜索。

哇,我没看到。我很抱歉。但无论如何,谢谢你抽出时间告诉我:D
 HtmlDocument doc = new HtmlDocument();
 doc.Load("file.htm");
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
 {
    HtmlAttribute att = link["href"];
    // DO SOMETHING WITH THE LINK HERE
 }
 doc.Save("file.htm");