C#通过特定的属性值删除特殊的html标签 [英] C# remove special html tags by specific attribute value
本文介绍了C#通过特定的属性值删除特殊的html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的 html 标签中,我想使用 c# 程序删除在 style
中具有属性值 "display:none"
的整个标签:
In the below html tags, I want to use c# programs to remove the whole tags which has the attribute values "display:none"
in style
:
<td>
<span style="display:none">
<font color="#ffffff">OK</font>
</span>
<span>
<font color="#ffffff">OK</font>
</span>
</td>
然后html会变成:
<td>
<span>
<font color="#ffffff">OK</font>
</span>
</td>
除了使用 Replace()
函数,谁能建议我一些方法来解决这个问题?
Besides using Replace()
function, Can anyone suggest me some ways to solve this problem?
推荐答案
幸运的是,您可以使用 在 C# 中使用 jQuery 之类的 sintaxysCsQuery
Fortunately you can use jQuery like sintaxys in C# using CsQuery
string htmlString = @"<td>
<span style=\"display:none\">
<font color=\"#ffffff\">OK</font>
</span>
<span>
<font color=\"#ffffff\">OK</font>
</span>
</td>";
var dom = CQ.Create(htmlString);
dom.Select("[style=display:none]").Remove();
我不测试它,但这是一个很好的起点
I don't test it but is a good starting point
在具有多个显示器的 DOM 中:无,正如评论中提到的@jamietre
In a DOM with more than one display:none, as metioned @jamietre in comments
var dom = CQ.Create(htmlString);
dom.Select("[style]").Where(item=>item.Style["display"]=="none")).Remove();
这篇关于C#通过特定的属性值删除特殊的html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文