HtmlAgilityPack: Get whole HTML document as string

deostroll picture deostroll · Mar 3, 2011 · Viewed 44.1k times · Source

Does HtmlAgilityPack have the ability to return the whole HTML markup from an HtmlDocument object as a string?

Answer

Simon Mourier picture Simon Mourier · Mar 3, 2011

Sure, you can do like this:

HtmlDocument doc = new HtmlDocument();
// call one of the doc.LoadXXX() functions
Console.WriteLine(doc.DocumentNode.OuterHtml);

OuterHtml contains the whole html.