当前位置: 移动技术网 > IT编程>开发语言>c# > C#提取网页中超链接link和text部分的方法

C#提取网页中超链接link和text部分的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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#正则表达式用法总结》及《c#字符串操作技巧总结

希望本文所述对大家c#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网