Parsing an HTML Page with HtmlAgilityPack to Select Divs by Class

I use C # with HtmlAgilityPack and I can select divs that have id foo

var foos = from foo in htmlDoc.DocumentNode.Descendants("div")
           where foo.Id == "foo" 
           select foo;

but how to select a div with class bar?

+5
source share
1 answer

You can use XPATH like this

//div[@class='bar'] 

or

//*/div[@class='bar']

You can also do && foo.Class == "bar".

+9
source

All Articles