C#如何删除UL及LI中指定标签里文字的方法详解


本文摘自PHP中文网,作者黄舟,侵删。

这篇文章主要介绍了C#删除UL LI中指定标签里文字的方法,涉及C#针对页面HTML元素进行正则匹配与替换的相关操作技巧,需要的朋友可以参考下

本文实例讲述了C#删除UL LI中指定标签里文字的方法。分享给大家供大家参考,具体如下:

现在需求越来越变态,但是做代码只能尽量满足,这里先是扣去ul和li中的超链接里的文字

1

2

3

4

5

6

7

8

9

10

11

12

13

PromptHtml = GetData.GetHTTPInfo(Config.Prompt_Url, "utf-8");

PromptHtml = PromptHtml.Replace("<ul><li>", "");

PromptHtml=PromptHtml.Replace("</li></ul>", "");

string ss = @"<a[\s\S]*?href=""([^" rel="external nofollow" "]*?)""[^>]*?>([\s\S]*?)</a>"; //这里

MatchCollection mcTable = Regex.Matches(PromptHtml, ss);

foreach (Match mTable in mcTable)

{

  if (mTable.Success)

  {

    PromptHtml = mTable.Groups[2].Value;

  }

}

resultHtml = PromptHtml;

具体的数据源如下:

代码如下:

1

<ul><li><a href="http://localhost/tg.aspx?ID=4194" rel="external nofollow" >哪些主题基金有望爆发?</a></li></ul>

这篇是扣去ul和li中的span里面的文字:

1

2

3

4

5

6

7

8

9

10

11

12

13

middlebannerHtml = GetData.GetHTTPInfo(Config.Middlebanner_Url, "utf-8");

middlebannerHtml = middlebannerHtml.Replace("<ul><li>", "");

middlebannerHtml = middlebannerHtml.Replace("</li></ul>", "");

string ss = @"<span>([^<]+)</span>"; //这里

MatchCollection mcTable = Regex.Matches(middlebannerHtml, ss);

foreach (Match mTable in mcTable)

{

  if (mTable.Success)

  {

    middlebannerHtml = mTable.Groups[1].Value;

  }

}

middleContent = middlebannerHtml;

具体的数据源如下:

代码如下:

1

<ul><li><span>3年5倍涨幅的 不只是股票哦~</span> <a href="http://localhost/tg.aspx?ID=4195" rel="external nofollow" >立即查看</a></li></ul>

以上就是C#如何删除UL及LI中指定标签里文字的方法详解的详细内容!

相关阅读 >>

C#入门经典学习阶段小结(凌乱)

C# tabcontral选项卡中加载显示窗体后 实现单向参数传递测试代码示例(图)

详解C#winform打开excel文档的方法总结

实现C#中图片.byte[]和base64string的转换方法的详解

C#中如何实现带百分比的进度条功能的示例代码分享

C#如何使用 oledbconnection 连接读取excel?(代码实例)

详解C#获取本机ip地址(ipv4)的代码案例

采用 C# 编写的学委助手详解及实例

C#和c ++的区别是什么

C#新建datacolumn类时type类型参数的生成方式的示例代码详解

更多相关阅读请进入《C#》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...