views:

201

answers:

1

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?

+1  A: 

You can use XPATH like //div[@class='bar'] or //*/div[@class='bar'], you also may be able to do && foo.Class == "bar".

Rodney Foley
Unfortunately there is no foo.Class how would I use xpath instead?
Nicholas Murray
Got it.: var foos = from foo in htmlDoc.DocumentNode.SelectNodes("//div[@class='bar']")select foo;
Nicholas Murray