C#获取html标签内容的方法
C# 获取html标签内容的方法:
////// 获取html网页标签内容 /// 例如: /// /// html内容 /// 标签 例如:span /// 标签属性 例如:class /// 标签属性值 例如:index_infoItem__ESU0o /// public static string[] RegexHtmlToFormat(string html, string tag, string attribute, string value) { List<string> list = new List<string>(); string regex_html = @"<"+ tag + ".*?"+ attribute + "=.*?"+ value + ".*?[^>]*?>.*?" + tag + ">"; //定义html标签的正则表达式 Regex regex = new Regex(regex_html, RegexOptions.IgnoreCase); if (regex.IsMatch(html)) { MatchCollection matchCollection = regex.Matches(html); foreach (Match match in matchCollection) { var valueHtml = match.Value; valueHtml = Regex.Replace(valueHtml, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);//去除html标签 list.Add(valueHtml);//获取到的 } } return list.ToArray(); }