Nicholas Murray
Nicholas Murray

Reputation: 13529

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?

Upvotes: 5

Views: 14909

Answers (1)

Rodney S. Foley
Rodney S. Foley

Reputation: 10340

You can use XPATH like this

//div[@class='bar'] 

or

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

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

Upvotes: 9

Related Questions