0

вот код

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScrapingDollarRate { internal class Episode { public string OverallNumber { get; set; } public string Title { get; set; } public string Directors { get; set; } public string WrittenBy { get; set; } public string Released { get; set; } } }

using HtmlAgilityPack; using CsvHelper; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Globalization;

namespace ScrapingDollarRate { class Program { static void Main(string[] args) { // the URL of the target dollar rate page string url = "https://www.banki.ru/products/currency/usd/";

        var web = new HtmlWeb();
        // downloading to the target page
        // and parsing its HTML content
        var document = web.Load(url);
        var nodes = document.DocumentNode.SelectNodes("div[class = 'Flexbox__sc-wtbhrg-0 hrHAlf']");

        List<Episode> episodes = new List<Episode>();
        foreach (var node in nodes)
        {
            // add a new Episode instance to
            // to the list of scraped data
            episodes.Add(new Episode()
            {
                OverallNumber = HtmlEntity.DeEntitize(node.SelectSingleNode("div[class = 'Text__sc-j452t5-0 hDxmZl']").InnerText),
                Title = HtmlEntity.DeEntitize(node.SelectSingleNode("div[class = 'Text__sc-j452t5-0 bCCQWi']").InnerText)
            });

        }

        // initializing the CSV file
        using (var writer = new StreamWriter("output.csv"))
        using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
        {
            // populating the CSV file
            csv.WriteRecords(episodes);
        }
    }
}

}

выскакивает ошибка System.NullReferenceException: 'Object reference not set to an instance of an object.'

  • https://ru.stackoverflow.com/questions/413041/%D0%A7%D1%82%D0%BE-%D1%82%D0%B0%D0%BA%D0%BE%D0%B5-nullreferenceexception-%D0%B8-%D0%BA%D0%B0%D0%BA-%D0%BC%D0%BD%D0%B5-%D0%B8%D1%81%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D1%82%D1%8C-%D0%BA%D0%BE%D0%B4 – air2921 Feb 06 '24 at 14:08

0 Answers0