易采站长站为您分析C#提取网页中超链接link和text部分的方法,涉及C#正则表达式及字符串操作相关技巧,需要的朋友可以参考下
注:相关教程知识阅读请移步到c#教程频道。
本文实例讲述了C#提取网页中超链接link和text部分的方法。,具体如下:
string s = "..";
Regex re = new Regex(@"<a[^>]*href=(""(?<href>[^""]*)""|'(?<href>[^']*)'|(?<href>[^s>]*))[^>]*>(?<text>.*?)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match m = re.Match(s);
if(m.Success)
{
string link = m.Groups["href"].Value;
string text = Regex.Replace(m.Groups["text"].Value,"<[^>]*>","");
Console.WriteLine("link:{0}ntext:{1}", link, text);
}
希望本文所述对大家C#程序设计有所帮助。
注:相关教程知识阅读请移步到c#教程频道。










