Blacker.Scraper.Helpers.WebHelper.GetHtmlDocument C# (CSharp) Method

GetHtmlDocument() public static method

Get HTML node of the remote website
public static GetHtmlDocument ( string url ) : HtmlNode
url string Website url
return HtmlAgilityPack.HtmlNode
        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);
            }
        }