C# html agility pack get elements by class name

前端 未结 5 903
忘了有多久
忘了有多久 2021-01-04 05:33

I\'m trying to get all the divs that their class contains a certain word:

content1
5条回答
  •  生来不讨喜
    2021-01-04 06:02

    As of version v1.6.5 of Html Agility Pack, it contains .HasClass("class-name") extension method.

    IEnumerable nodes =
        htmlDoc.DocumentNode.Descendants(0)
            .Where(n => n.HasClass("class-name"));
    

提交回复
热议问题