如何从HTML删除分区的内容和使用HTML敏捷包放置相同的所有div的顶部 [英] how to remove div content from html and place the same on top of all divs using html agility pack
本文介绍了如何从HTML删除分区的内容和使用HTML敏捷包放置相同的所有div的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我与HTML敏捷包出现问题,我无法删除HTML DIV内容并在所有div的顶部相同的内容。像
i have a problem with html agility pack i am unable to remove div content from html and place the same content on top of all divs. like
<body>
<div class="1">...</div>
<div class="2">...</div>
<div class="3">...</div>
</body>
现在我想删除/排序第三格,将其放在第一个div的顶部。
任何帮助将是巨大的。谢谢!
now i want to remove/sort third div and place it on top of first div. Any help would be great. Thanks!
推荐答案
您应该试试这个code:
You should try this code:
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml("<html><body><div class=\"1\">...</div><div class=\"2\">...</div><div class=\"3\">...</div></body></html>");
HtmlNode body = doc.DocumentNode.SelectSingleNode("/html/body");
HtmlNode div = body.SelectSingleNode("div[@class='3']");
if (div != null) {
div.Remove();
body.InsertBefore(div, body.FirstChild);
}
这篇关于如何从HTML删除分区的内容和使用HTML敏捷包放置相同的所有div的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文