HTML Agility Pack HtmlDocument Show All Html?

22,935

DocumentNode.OuterHtml contains the full html:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load("sample.html");
string html = doc.DocumentNode.OuterHtml;

In your example:

public static string GetWebPageHtmlFromUrl(string url)
{
    var hw = new HtmlWeb();
    HtmlDocument doc = hw.Load(url);
    return doc.DocumentNode.OuterHtml;
}
Share:
22,935
YodasMyDad
Author by

YodasMyDad

Updated on July 09, 2022

Comments

  • YodasMyDad
    YodasMyDad almost 2 years

    I am using the following to get a web page which works fine

        public static HtmlDocument GetWebPageFromUrl(string url)
        {
            var hw = new HtmlWeb();
            return hw.Load(url);
        }
    

    But how to I spit the entire contents of the HTML out from the HtmlDocument into a string?

    I tried HtmlDocument.ToString() but that doesn't give me all the HTML in the document? Any ideas?

  • Muhammad Akhtar
    Muhammad Akhtar about 13 years
    +1, as I have not understand the question and did not answer properly and deleted my answer.