.NET Core 2.1 Web Scraper 控制台输出“HtmlAgilityPack.HtmlDocument
.NET Core 2.1 Web Scraper Console Outputting "HtmlAgilityPack.HtmlDocument
我正在尝试使用 .NET Core 2.1 和 HtmlAgilityPack 创建网络抓取工具,从 na.op.gg 中提取英雄联盟统计数据。
这是我的代码:
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();
}
}
}
对于 XPath,我只是进入 Chrome,检查元素,并复制 XPath 以获得获胜率统计数据。
当我 运行 我的程序时,我得到以下控制台输出:
HtmlAgilityPack.HtmlNode
我不确定自己做错了什么……有什么想法吗?非常感谢!
champ WinRate 是一个对象。尝试检查其属性之一,例如 InnerText
.
我正在尝试使用 .NET Core 2.1 和 HtmlAgilityPack 创建网络抓取工具,从 na.op.gg 中提取英雄联盟统计数据。
这是我的代码:
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();
}
}
}
对于 XPath,我只是进入 Chrome,检查元素,并复制 XPath 以获得获胜率统计数据。
当我 运行 我的程序时,我得到以下控制台输出:
HtmlAgilityPack.HtmlNode
我不确定自己做错了什么……有什么想法吗?非常感谢!
champ WinRate 是一个对象。尝试检查其属性之一,例如 InnerText
.