remove html node from htmldocument :HTMLAgilityPack

前端 未结 4 615
闹比i
闹比i 2020-12-16 18:17

In my code, I want to remove the img tag which doesn\'t have src value. I am using HTMLAgilitypack\'s HtmlDocument object. I am finding the img whic

4条回答
  •  没有蜡笔的小新
    2020-12-16 18:41

    var emptyElements = doc.DocumentNode
        .Descendants("a")
        .Where(x => x.Attributes["src"] == null || x.Attributes["src"].Value == String.Empty)
        .ToList();
    
    emptyElements.ForEach(node => {
        if (node != null){ node.Remove();}
    });
    

提交回复
热议问题