Skip to content Skip to sidebar Skip to footer

Htmlagilitypack Htmlweb.load Returning Empty Document

I have been using HtmlAgilityPack for the last 2 months in a Web Crawler Application with no issues loading a webpage. Now when I try to load a this particular webpage, the documen

Solution 1:

It seems this website requires cookies to be enabled. So creating a cookie container for your web request should solve the issue:

var url = "http://www.prettygreen.com/";
var htmlWeb = new HtmlWeb();
htmlWeb.PreRequest += request =>
    {
        request.CookieContainer = new System.Net.CookieContainer();
        return true;
    };
var htmlDoc = htmlWeb.Load(url);
var outerHtml = htmlDoc.DocumentNode.OuterHtml;
Assert.AreNotEqual("", outerHtml);

Post a Comment for "Htmlagilitypack Htmlweb.load Returning Empty Document"