Html Agility Pack/SgmlReader 解析html
Html Agility Pack/SgmlReader 解析html
HtmlDocument htmlDoc = new HtmlDocument(); //输出成xml格式 htmlDoc.OptionOutputAsXml = true; / 加载html内容 htmlDoc.LoadHtml(@"<html><body> <table> <tr> <td>dafd</td> <td> </tr> </table> </body></html>"); // 将输出结果保存到字符串流中 StringBuilder sbXml = new StringBuilder(); StringWriter sw = new StringWriter(sbXml); htmlDoc.Save(sw); Console.WriteLine(sbXml.ToString()); StringBuilder sbXml = new StringBuilder(); StringWriter sw = new StringWriter(sbXml); XmlTextWriter tw = new XmlTextWriter(sw); HtmlWeb htmlWeb = new HtmlWeb(); htmlWeb.LoadHtmlAsXml("http://htmlagilitypack.codeplex.com/", tw); Console.WriteLine(sbXml.ToString());