Html Agility Pack get all elements by class
Posted
by
Adam
on Stack Overflow
See other posts from Stack Overflow
or by Adam
Published on 2012-12-07T21:15:47Z
Indexed on
2012/12/07
23:04 UTC
Read the original article
Hit count: 750
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.Descendants("div").Where(d => d.Attributes.Contains("class"));
However, obviously you can add classes to a lot more then divs so I tried this.. var allLinksWithDivAndClass = _doc.DocumentNode.SelectNodes("//*[@class=\"float\"]");
But that doesn't handle the cases where you add multiple classes and "float" is just one of them like this..
class="className float anotherclassName"
Is there a way to handle all of this? I basically want to select all nodes that have a class = and contains float.
© Stack Overflow or respective owner