简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM