I'm trying to create a web scraper with .NET Core 2.1 & HtmlAgilityPack that pulls League of Legends stats from na.op.gg.
Here's my code:
using System;
using System.Net.Http;
using System.Threading.Tasks;
using HtmlAgilityPack;
namespace WebScraper
{
class Program
{
static void Main(string[] args)
{
{
MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
}
}
async static Task MainAsync(string[] args)
{
HttpClient client = new HttpClient();
var response = await client.GetAsync("http://na.op.gg/summoner/userName=Mr%20BalIoon%20Hands");
var pageContents = await response.Content.ReadAsStringAsync();
HtmlDocument pageDocument = new HtmlDocument();
pageDocument.LoadHtml(pageContents);
var champWinRate = pageDocument.DocumentNode.SelectSingleNode("//*[@id=\"SummonerLayoutContent\"]/div[2]/div[1]/div[2]/div[2]/div[1]/div/div[1]/div[4]/div[2]");
Console.WriteLine(champWinRate);
Console.ReadLine();
}
}
}
For the XPath, I simply went onto Chrome, inspected element, and copied the XPath for a win rate statistic.
When I run my program, I get the following console output:
HtmlAgilityPack.HtmlNode
I'm not sure what I'm doing wrong... any ideas? Thanks so much!
champWinRate is an object. Try inspecting one of it's properties like InnerText
.