3

Following this example, I can find the LI sections.

Html Agility Pack - Parsing <li>

However, I only want the LI items that reside inside the div with an id of "res".

How do I do that?

1 Answer 1

6

Something like this:

List facts = new List();
foreach (HtmlNode li in doc.DocumentNode.SelectNodes("//div[@id='res']/li")) {
    facts.Add(li.InnerText);
}
XPath Checker might also help you with future XPath queries.

Sign up to request clarification or add additional context in comments.

2 Comments

All correct, but may want to check HtmlNodeCollection for null in the event none exist.
Excellent! And thanks for the XPatch Checker tip too. I can definitely use that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.