public static HtmlNode GetHtmlDocument(string url)
{
if (url == null)
throw new ArgumentNullException("url");
HtmlDocument doc = new HtmlDocument();
try
{
var stopWatch = new Stopwatch();
stopWatch.Start();
var request = (HttpWebRequest)HttpWebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
doc.Load(stream, true);
}
stopWatch.Stop();
_log.DebugFormat("Download of URL '{0}' took '{1}'", url, stopWatch.Elapsed);
return doc.DocumentNode;
}
catch (WebException ex)
{
throw new HttpException("Could not load remote website.", ex);
}
catch (IOException ex)
{
throw new HttpException("Could not load remote website.", ex);
}
catch (Exception ex)
{
throw new ParserException("Could not process remote website request.", ex);
}
}