Question

 HtmlDocument doc = new HtmlDocument();
    doc.Load(yourhtml);
    doc.Save(Console.Out);

How to save this into an string instead of Console.Out

Was it helpful?

Solution

string s = doc.DocumentNode.OuterHtml;

or

var sw = new StringWriter();
doc.Save(sw);
var s = sw.ToString();

OTHER TIPS

how about

string  html = doc.DocumentNode.OuterHtml;

OuterHTML will have the Entire HTML..

string s = doc.DocumentNode.OuterHtml

Why not using this:

var str = File.ReadAllText(yourHtml);

It will read your html document to string without initializing HtmlDocument object. Is yourHtmlreally a html or just a path? HtmlAgilityPack.HtmlDocument does not contain Load method accepting html.

string variableName = doc.DocumentNode.OuterHtml;
   HtmlDocument doc = new HtmlDocument();
   // call one of the doc.LoadXXX() functions
   Console.WriteLine(doc.DocumentNode.OuterHtml);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top