【问题标题】:.NET Core 2.1 Web Scraper Console Outputting "HtmlAgilityPack.HtmlDocument.NET Core 2.1 Web Scraper 控制台输出“HtmlAgilityPack.HtmlDocument
【发布时间】:2018-11-27 21:43:28
【问题描述】:

我正在尝试使用 .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

我不确定我做错了什么......有什么想法吗?非常感谢!

【问题讨论】:

  • champWinRate 是一个对象。尝试检查其中一个属性,例如InnerText
  • @mr.coffee 哈哈,这行得通。谢谢!!
  • 欢迎您。如果您想将您的问题标记为已回答,我添加了我的评论作为答案:)
  • @mr.coffee 当然,它不会让我再标记 8 分钟,但我一定会这样做 :)

标签: c# asp.net web-scraping html-agility-pack


【解决方案1】:

champWinRate 是一个对象。尝试检查其中一个属性,例如 InnerText

【讨论】:

    猜你喜欢
    • 2018-11-16
    • 1970-01-01
    • 2018-11-26
    • 2019-03-25
    • 2017-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多