Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing HTML page with HtmlAgilityPack to select Divs by class

I am using C# with HtmlAgilityPack and I can select divs that have an id of foo

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

but how do I select div's with a class of bar?

like image 323
Nicholas Murray Avatar asked Apr 16 '10 21:04

Nicholas Murray


1 Answers

You can use XPATH like this

//div[@class='bar'] 

or

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

You also may be able to do && foo.Class == "bar".

like image 131
Rodney S. Foley Avatar answered Oct 18 '22 11:10

Rodney S. Foley