c#正则获取html标题
发布日期:2018-02-05 浏览次数:739
private static string GetTitle(string html) { string titleFilter = @"[\s\S]*? "; string h1Filter = @".*?"; string clearFilter = @"<.*?>"; string title = ""; Match match = Regex.Match(html, titleFilter, RegexOptions.IgnoreCase); if (match.Success) { title = Regex.Replace(match.Groups[0].Value, clearFilter, ""); } //获取h1标题 match = Regex.Match(html, h1Filter, RegexOptions.IgnoreCase); if (match.Success) { string h1 = Regex.Replace(match.Groups[0].Value, clearFilter, ""); if (!String.IsNullOrEmpty(h1) && title.StartsWith(h1)) { title = h1; } } return title; }
上一篇: c#根据网址读取网页内容
下一篇: c#定义正则表达式用来匹配img标签
本文网址:https://www.wyxxw.cn/blog-detail-2-6-59.html
非特殊说明,本文版权归原作者所有,转载请注明出处
提示:本站所有资源仅供学习与参考,请勿用于商业用途。图片来自互联网~如侵犯您的权益,请联系QQ:1067507709.
提示:转载请注明来自:https://www.wyxxw.cn/blog-detail-2-6-59.html 。 本文发布者:momo