-1

I want to get the stats of a player in a game, and show these in my application. The stats I need are put online on a website(account.xxx.com/player/username).

How to I grab (for example) the kill/death ratio from that website?

Remi
  • 49
  • 10
  • 2
    The OP and upvoter perhaps should revisit the [ask] article. Question shows no attempt nor sign of research –  Jan 10 '16 at 13:05

3 Answers3

1

Screen scrape the page into code, then walk the resulting markup to get the values you need. E.g. regular expression, DOM parsing, Linq to Xml etc, ...

"Screen scraping" is the act of calling a page into code into a variable, rather than rendering onto a browser. Once you have the page in code as a variable you can manipulate it however you desire.

Community
  • 1
  • 1
NikolaiDante
  • 18,469
  • 14
  • 77
  • 117
  • Sorry but I got no idea what you are talking about.. I looked at that screen scraping but I don't understand it, i'm sorry I've never done something like this before.. – Remi Jan 10 '16 at 12:57
  • 1
    @RemivanBuuren Don't understand? Never done before? There's always a first time for anything. Do some googling and learn. Nikolai's idea has some merit. Don't expect us to write your app for you –  Jan 10 '16 at 13:03
  • @Micky I found a video tutorial on screen scraping, I think it will work out. I should look further then my nose is long more often, thanks. – Remi Jan 10 '16 at 13:13
  • @RemivanBuuren Well done –  Jan 10 '16 at 13:58
1

The first thing I must stress is:

Make sure it is not against the ToS of the website for you to use their data in this manner.

So, for example:

// Store the URL of the website you are looking at.
string path = "http://euw.op.gg/summoner/userName=";
string userName = "froggen";
string url = path + userName;
// Create a new WebClient to download the html page.
using (WebClient client = new WebClient())
{
    // Download the html source code of the user page.
    string html = client.DownloadString(url);

    // Finding the kda depends on the website - you need to know what you are looking for. Have a look at the page source and see where the kda is stored.
    // I've had a look at the source of my example and I know kda is stored in <span class="KDARatio">3.92:1</span>.

    // You'll need a way to get that data out of the HTML - you might try to parse the file and traverse it.
    // I've chosen Regex to match the data I'm looking for.
    string pattern = @"<span class=""KDARatio"">\d+\.\d+";
    // I take the first string that matches my regex from the document.
    string kdaString = Regex.Matches(html, pattern)[0].Value;
    // I trim the data I don't need from it.
    string substring = kdaString.Substring(kdaString.IndexOf('>') + 1);
    // Then I can convert it into a double - giving me the x:1 kda ratio for this player.
    double kda = double.Parse(substring);
};

As others have suggested, you should have a look at how to ask a good question. It is generally considered bad etiquette to ask people to solve your problem for you without demonstrating what you have attempted yourself.

Community
  • 1
  • 1
TVOHM
  • 2,740
  • 1
  • 19
  • 29
  • This looks more like what I hoped to find, i'll test this out as soon as I get back home! – Remi Jan 10 '16 at 13:45
0

use the HtmlAgilityPack to pull the info you need from the html

SuncoastOwner
  • 263
  • 2
  • 9