html agility pack remove children

前端 未结 3 883
一整个雨季
一整个雨季 2021-01-23 17:04

I\'m having difficulty trying to remove a div with a particular ID, and its children using the HTML Agility pack. I am sure I\'m just missing a config option, but its Friday a

相关标签:
3条回答
  • 2021-01-23 17:52

    bodyNode.RemoveChild(functionBarNode,false);

    But functionBarNode is not a child of bodyNode.

    How about functionBarNode.ParentNode.RemoveChild(functionBarNode, false)? (And forget the bit about finding bodyNode.)

    0 讨论(0)
  • 2021-01-23 17:58

    You can simply call:

    var documentNode = document.DocumentNode;
    var functionBarNode = documentNode.SelectSingleNode("//div[@id='functionBar']");
    functionBarNode.Remove();
    

    It is much simpler, and does the same as:

    functionBarNode.ParentNode.RemoveChild(functionBarNode, false);
    
    0 讨论(0)
  • 2021-01-23 18:08

    This will work for multiple:

    HtmlDocument d = this.Download(string.Format(validatorUrl, Url));
    foreach (var toGo in QuerySelectorAll(d.DocumentNode, "p[class=helpwanted]").ToList())
    {
       toGo.Remove();
    }
    
    0 讨论(0)
提交回复
热议问题