HtmlAgilityPack不能解析<select><option>的解决方法

用HtmlAgilityPack对下拉列表进行解析时,会得到一个错误提示,说<option>不能有闭合的</option>,实际解析结果也有问题。

查了下资料,在 HTML 中,<option> 没有结束标签,而在XHTML 中,<option> 必须被正确关闭。(见http://www.w3school.com.cn/tags/tag_option.asp

 

解决方法很简单,HtmlNode.ElementsFlags.Remove("option")就可以了,如下所示:

 

HtmlDocument htmlDocu = new HtmlDocument();
HtmlNode.ElementsFlags.Remove("option");
htmlDocu.LoadHtml(content);
 
参见http://stackoverflow.com/questions/4758644/parsing-html-with-html-agillity-pack
posted @ 2011-05-31 11:54  夏夜的二进制旅行  阅读(1486)  评论(5编辑  收藏  举报