HtmlAgilityPack uses the XPath selector to select nodes.
For your problem, this will work:
HtmlDocument doc = new HtmlDocument(); doc.Load(@"test.html"); var l1s = doc.DocumentNode.SelectNodes("//l1"); foreach (var item in l1s) { var links = item.SelectNodes("a"); }
Please note that I used the XPath selector, which will capture all l1 elements in the document (using the leading // ), more specifically you can also do:
var l1s = doc.DocumentNode.SelectNodes("root/p1/l1");
Brokenglass
source share