C #, parsing HTML page, using Agility Pack

Following this example, I can find LI sections.

Html Agility Pack - <li> Analysis

However, I only need the LI elements that are inside the div with the identifier "res".

How to do it?

+3
source share
1 answer

Something like that:

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

Source: https://habr.com/ru/post/1732600/


All Articles