/************************************************************** * GetResponseDocument * Parse the response stream and cache it for reuse. Uses the * HtmlAgilityPack library for the heavy lifting. **************************************************************/ public static HtmlDocument GetResponseDocument(this HttpWebResponse r) { if (!documentCache.ContainsKey(r)) { try { HtmlDocument doc = new HtmlDocument(); doc.Load(r.GetResponseStreamCopy()); //Always Cache documentCache.Add(r, doc); } catch (Exception e) { throw new Exception("Unable to load HtmlDocument from Response Stream. " + e.Message); } } return(documentCache[r]); }