I'm trying to get Html Agility Pack to work in my case. I need to detect all script el开发者_StackOverflow社区ements in an existing HTML page and remove them, saving the changes to another file. Here, bodyNode returns the correct number of script tags, but I can't remove them. The new file still has those tags.
if (doc.DocumentNode != null)         
{
     var bodyNode = doc.DocumentNode.SelectNodes("//script");          
     if (bodyNode != null)             
     {
          bodyNode.Clear(); // clears the collection only                    
     } 
     doc.Save("some file");        
 }
You need to do something like this:
foreach(HtmlNode node in bodyNode)
{
   node.ParentNode.RemoveChild(node);
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论