C#提取网页中超链接link和text部分的方法
本文实例讲述了C#提取网页中超链接link和text部分的方法。分享给大家供大家参考,具体如下:
strings="..";
Regexre=newRegex(@"<a[^>]*href=(""(?<href>[^""]*)""|'(?<href>[^']*)'|(?<href>[^\s>]*))[^>]*>(?<text>.*?)</a>",RegexOptions.IgnoreCase|RegexOptions.Singleline);
Matchm=re.Match(s);
if(m.Success)
{
stringlink=m.Groups["href"].Value;
stringtext=Regex.Replace(m.Groups["text"].Value,"<[^>]*>","");
Console.WriteLine("link:{0}\ntext:{1}",link,text);
}
更多关于C#相关内容感兴趣的读者可查看本站专题:《C#正则表达式用法总结》及《C#字符串操作技巧总结》
希望本文所述对大家C#程序设计有所帮助。