这篇文章主要介绍了C#删除UL LI中指定标签里文字的方法,涉及C#针对页面HTML元素进行正则匹配与替换的相关操作技巧,需要的朋友可以参考下
这篇文章主要介绍了C#删除UL LI中指定标签里文字的方法,涉及C#针对页面HTML元素进行正则匹配与替换的相关操作技巧,需要的朋友可以参考下
这篇文章主要介绍了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; |
具体的数据源如下:
这篇是扣去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; |
具体的数据源如下:
希望本文所述对大家C#程序设计有所帮助。
发表评论