diff --git a/Dota2AdvancedDescriptions/Tools/DotaHtmlParser.cs b/Dota2AdvancedDescriptions/Tools/DotaHtmlParser.cs index 5dffe23..84261dd 100644 --- a/Dota2AdvancedDescriptions/Tools/DotaHtmlParser.cs +++ b/Dota2AdvancedDescriptions/Tools/DotaHtmlParser.cs @@ -39,27 +39,35 @@ public void ParseData(string address, string xpath) StatusBarHelper.Instance.SetStatus(String.Format("Downloading data from {0}", address.Replace("http://", string.Empty))); ServicePointManager.DefaultConnectionLimit = int.MaxValue; - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address); - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + string page = ""; - if (response.StatusCode == HttpStatusCode.OK) + for (int i = 0; i < 5 && string.IsNullOrEmpty(page); i++) //For some reason every now and then gamepedia returns an empty body, so I try an arbitrary number of times { - Stream receiveStream = response.GetResponseStream(); - StreamReader readStream = null; + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address); + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - if (response.CharacterSet == null) - { - readStream = new StreamReader(receiveStream); - } - else + if (response.StatusCode == HttpStatusCode.OK) { - readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)); - } + Stream receiveStream = response.GetResponseStream(); + StreamReader readStream = null; + + if (response.CharacterSet == null) + { + readStream = new StreamReader(receiveStream); + } + else + { + readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)); + } - page = readStream.ReadToEnd(); + page = readStream.ReadToEnd(); - response.Close(); - readStream.Close(); + response.Close(); + readStream.Close(); + } else + { + break; + } } HtmlDocument doc = new HtmlDocument();