我正在尝试从 HTML 字符串中删除一些 HTML 标记。
我的 HTML 如下所示:
<p>Dont want to remove this tag</p>
<p class="MsoNormal"><font face="Times New Roman">Remove all Tag after this tag except style</font><p>some more text here</p><a>some more text here</a></p>
<p>dsa</p>
<p>dsa</p>
<p>dsa</p>
<p>dsa</p>
<p></p>
.... more tags here but all are <p> with some nested p and span
<p>dsa</p>
<p></p>
<p>dsa</p>
<p>Last tag to be removed</p>
<style>some style</style>
我试过的是
var element = dom["p:Contains(\"Remove all Tag after this tag\")"];
if (element!=null)
{
var newHTML = dom[element.Selector.ToString()].Remove();
}
但它不工作。它给了我删除的节点。我想要删除节点后剩余的 html。CSQuery 甚至 .NET 字符串替换解决方案也适用于我。
预期结果是
<p>Dont want to remove this tag</p>
<style>some style</style>