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

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

有帮助吗?

解决方案

string s = doc.DocumentNode.OuterHtml;

or

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

其他提示

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top