源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-08-26 13:03 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C#提取网页中超链接link和text部分的方法
本文实例讲述了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#相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/344.htm]C#正则表达式用法总结[/url]》及《[url=http://www.1sucai.cn/Special/261.htm]C#字符串操作技巧总结[/url]》 希望本文所述对大家C#程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部