Pull score from online game's HTML

This is going to be a very weird and oddly specific question. I have a WinForms project that I want to have check the score of an online game. If we're being specific here, I want to pull the player's time from https://www.tetrisfriends.com/games/Sprint/game.php when the game ends. The time is in the website's HTML, and I was wondering if there was any way to periodically check the HTML for a time every few seconds, and if there is one there, pull it into my code. I know that probably made no sense, but please let me know if you have any idea on how I would even start with something like this. Thanks!

(By the way, I don't know if this would simplify it in any way, but I am fine if it just works on a single browser like Chrome)

1 answer

  • answered 2018-08-16 05:39 Ido H Levi

    If you want to get the site's HTML you can use this code:

    string urlAddress = "http://google.com";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    if (response.StatusCode == HttpStatusCode.OK)
      Stream receiveStream = response.GetResponseStream();
      StreamReader readStream = null;
      if (response.CharacterSet == null)
         readStream = new StreamReader(receiveStream);
         readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
      string data = readStream.ReadToEnd();

    And then just search where the score and everything else you want by just how you would search any normal string.