C# 获取html标签内容的方法:

        /// <summary>
/// 获取html网页标签内容
/// 例如:<span class="index_infoItem__ESU0o"></span>
/// </summary>
/// <param name="html">html内容</param>
/// <param name="tag">标签 例如:span</param>
/// <param name="attribute">标签属性 例如:class</param>
/// <param name="value">标签属性值 例如:index_infoItem__ESU0o</param>
/// <returns></returns>
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();
}

最新文章

  1. 【Swift学习】Swift编程之旅---继承(十七)
  2. charles使用教程指南(抓包工具)
  3. ecshop后台通过ajax搜索原理
  4. 《TCP/IP具体解释卷2:实现》笔记--IP多播
  5. [MVC] - 异步调用后台的常用方法。
  6. update语句
  7. jQuery编写插件--封装全局函数的插件(一些常用的js验证表达式)
  8. 修改Calendar(梅花雨)日历控件 兼容IE9 谷歌 火狐
  9. C/C++各种类型int、long、double、char表示范围(最大和最小)
  10. X-NUCA 2017 web专题赛训练题 阳光总在风雨后和default wp
  11. Bash shell命令记录和CentOS的一些技巧
  12. JMeter监控服务器CPU、内存的方法
  13. Python学习之路基础篇--07Python基础+编码、集合 和 深浅Copy
  14. Android 指定 Theme
  15. 05. .stop、.prevent、.capture、.self、.once、
  16. ODBC 驱动程序管理器 在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配 解决方案
  17. Linux学习笔记07—mysql的配置
  18. 迷你MVVM框架 avalonjs 1.3.9发布
  19. c++之单例模式
  20. ACM训练大纲

热门文章

  1. JUC学习笔记——共享模型之不可变
  2. SpringBoot+hutool工具-数据库数据导出Excel
  3. 解决Linux使用deepin-wine跑qq,tim打不开文件所在文件夹
  4. python-面向对象属性的访问与self的理解
  5. day02 数据类型 &amp; 运算符
  6. 【Shell案例】【for循环、seq生成】3、输出7的倍数
  7. 笔试面试--Java基础知识
  8. Spring学习笔记 - 第二章 - 注解开发、配置管理第三方Bean、注解管理第三方Bean、Spring 整合 MyBatis 和 Junit 案例
  9. 布尔值、元组、集合、input、格式化输出、赋值、运算符
  10. 动态更改Spring定时任务Cron表达式的优雅方案