Html Agility Pack get all elements by class

前端 未结 5 1646
失恋的感觉
失恋的感觉 2020-12-04 10:48

I am taking a stab at html agility pack and having trouble finding the right way to go about this.

For example:

var findclasses = _doc.DocumentNode.D         


        
5条回答
  •  醉话见心
    2020-12-04 11:05

    I used this extension method a lot in my project. Hope it will help one of you guys.

    public static bool HasClass(this HtmlNode node, params string[] classValueArray)
        {
            var classValue = node.GetAttributeValue("class", "");
            var classValues = classValue.Split(' ');
            return classValueArray.All(c => classValues.Contains(c));
        }
    

提交回复
热议问题