HtmlAgilityPack: Get whole HTML document as string

C#Html Agility-Pack

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

You can create WebRequest passing Url and Get webResponse . Get ResponseStream from WebResponse and read it into a String.

string result = string.Empty;

WebRequest req = WebRequest.Create(Url);
WebResponse res= wrq.GetResponse();    
StreamReader reader = new StreamReader(res.GetResponseStream());
result = reader.ReadToEnd();    
reader.Close();
res.Close();

Hope this helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondeostrollView Question on Stackoverflow
Solution 1 - C#Simon MourierView Answer on Stackoverflow
Solution 2 - C#budaView Answer on Stackoverflow