XHTML Parsing with HTMLAgilityPack

青春壹個敷衍的年華 提交于 2019-12-02 02:45:28

By default, the <OPTION> tag is treated by Html Agility Pack as a "Empty", which means it does not need a closing </OPTION>, that's why in this case, it's not easy to catch with XPATH. You can change this using the HtmlNode.ElementFlags collection.

Here is a code that should do what you want:

HtmlDocument doc = new HtmlDocument();
HtmlNode.ElementsFlags.Remove("option");
doc.LoadHtml(yourHtml);
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//option"))
{
    Console.WriteLine(node.InnerText);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!