How to get div by class in HtmlAgilityPack?

c# html-agility-pack windows-phone-8

Question

I'm following this tutorial, but I have a problem, I don't know how to get htmlNode by class name .

HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
htmlDoc.LoadHtml(e.Result);
HtmlNode divContainer = htmlDoc.GetElementbyId("directoryItems");//My problem here,I want to get by class name html
if (divContainer != null)
{
     HtmlNodeCollection nodes = divContainer.SelectNodes("//table/tr");
     ....
}
1
2
4/15/2014 9:52:41 AM

Popular Answer

Try this:

HtmlNodeCollection divContainer = htmlDoc.DocumentNode.SelectNodes("//div[@class='myClass']");

this will return a collection of div nodes with class="myClass"

2
4/15/2014 9:44:12 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow