开发者

Parsing HTML page with HtmlAgilityPack to select Divs by class

开发者 https://www.devze.com 2022-12-26 23:43 出处:网络
I am using 开发者_StackOverflowC# with HtmlAgilityPack and I can select divs that have an id of foo

I am using 开发者_StackOverflowC# 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?


You can use XPATH like this

//div[@class='bar'] 

or

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消