Skip to content

Commit

Permalink
"Fixed" cases where gamepedia returns an empty body "sometimes"
Browse files Browse the repository at this point in the history
  • Loading branch information
FilippoVigani committed Feb 25, 2017
1 parent 2a93587 commit b238e5b
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions Dota2AdvancedDescriptions/Tools/DotaHtmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b238e5b

Please sign in to comment.