public static HtmlDocument DownLoadHtml(string url) { Stream stream = null; StreamReader streamReader = null; HtmlDocument htmlDocument = null; sw.Restart(); try { stream = new MyWebClient().OpenRead(url); } catch (Exception e) { Console.WriteLine(e); return(htmlDocument); } try { if (stream == null) { return(null); } streamReader = new System.IO.StreamReader(stream, System.Text.Encoding.GetEncoding(65001)); htmlDocument = new HtmlAgilityPack.HtmlDocument(); if (htmlDocument == null) { return(null); } htmlDocument.LoadHtml(streamReader.ReadToEnd()); streamReader.Close(); stream.Close(); sw.Stop(); } catch (Exception e) { sw.Stop(); Utility.logger.Debug(sw.Elapsed); Utility.logger.Debug(e.Message); streamReader.Close(); stream.Close(); //If There is not html page. throw e; } return(htmlDocument); }