0

I am trying to write this script that pulls my stats from the steam api. I follow many other tutorials and based my code mostly on these posts: Parsing HTML page with HtmlAgilityPack and C# - How do I get the URL of an icon from Steam Trading API (encoded) But when I run my project it just returns a blank screen, with no error codes or anything. Here's the source code:

using HtmlAgilityPack;
using System;
using System.Xml.XPath;

namespace csgo_stats
{
    class Program
    {
        static void Main(string[] args)
        {
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml("http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&steamid=76561197972495328");
            XPathNavigator docNav = doc.CreateNavigator();
            XPathNavigator stats = docNav.SelectSingleNode("/html/body/pre");
            Console.WriteLine(stats);
            Console.ReadKey(); 
        }

    }
}
Community
  • 1
  • 1
Braden Parks
  • 51
  • 1
  • 10
  • It seems like your `XPathNavigator kills` variable is storing null or empty string, meaning your `docNav.SelectSingleNode(...)` query isn't returning any valid data. – Patrick Bell May 23 '16 at 21:52
  • If `1474` is the number of your actual kills, it is **not** inside a list element but rather in a paragraph: `/html/body/div[3]/main/section[1]/div/ul[1]/li[1]/div/p` – Jan May 23 '16 at 21:54
  • @jan I'll try that out and see if it works – Braden Parks May 23 '16 at 21:55
  • @Jan , with that xpath you gave me it still returns a blank line – Braden Parks May 23 '16 at 21:57
  • @BradenParks: What about: `//p[@class='current'][1]` ? – Jan May 23 '16 at 21:59
  • @Jan sorry no still just getting blank line – Braden Parks May 23 '16 at 22:00
  • @ext0 do you know how I would be able to fix that? – Braden Parks May 23 '16 at 22:53
  • @Jan I am trying a new site but still am having the same problem. Do you think you can help? – Braden Parks May 24 '16 at 03:53
  • Off topic, but I'd strongly suggest using something like [AngleSharp](https://github.com/AngleSharp/AngleSharp) or the (unfortunately no-longer-maintained) [CsQuery](https://github.com/jamietre/CsQuery) instead of HtmlAgilityPack - they provide much simpler ways of querying the DOM, particularly if you're already familiar with libraries like jQuery. – Ian Kemp May 24 '16 at 06:37

0 Answers0