Eric Burdo
Eric Burdo

Reputation: 33

C#, parsing HTML page, using HTML Agility Pack

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?

Upvotes: 3

Views: 1786

Answers (1)

Shane Fulmer
Shane Fulmer

Reputation: 7708

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.

Upvotes: 6

Related Questions