문제

 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