如何使用HTMLAgilitypack循環遍歷HTML的每個節點並刪除某些節點?

c# dom html-agility-pack

我需要識別每個節點並刪除某些節點,如Plegend 。需要使用HTMLAgilityPack遍歷以下html,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><META content="IE=5.0000" http-equiv="X-UA-Compatible">

<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
</HEAD>
<BODY bgcolor="white"><text><TITLE>ABCD</TITLE> 

<P style="page-break-before: always;">
<HR width="100%" size="3" align="CENTER" style="color: rgb(153, 153, 153);">

<fieldset>
    <legend>Personalia:</legend>
    Name: <input type="text"><br>
    Email: <input type="text"><br>
    Date of birth: <input type="text">
  </fieldset>

<P style="margin-top: 0px; margin-bottom: 0px;"><FONT size="1">&nbsp;</FONT></P>
<P align="center" style="margin-top: 0px; margin-bottom: 0px;"><FONT size="2" 
style="font-family: Times New Roman;">B-17 </FONT></P></text>

</BODY></HTML>

一般承認的答案

我只是舉個例子,嘗試一下

                String content = "Your Html page source as string";
                HtmlNode.ElementsFlags.Remove("form");
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(content);

                // Pass the name of the tag you want to remove 
                DeleteTagByName("tagname",doc);
                public void DeleteTagByName(string name, HtmlDocument HtmlDocument)
                 {
                     HtmlDocument.DocumentNode.SelectSingleNode("//input[@name='" + name + "']").Remove();

                } 



許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因