0

Помогите, пожалуйста, как правильно указать путь к html-классам сайта? (Хочу запарсить все таблицы с названиями команд и отдельно с коэффициентами. Уже месяц пытаюсь, не могу и не знаю как правильно указать путь к таблицам (46, 51, 54, 57, 63 строки) Если что, ссылка на сам сайт: https://parisportif.pmu.fr/home/wrapper/dashboard?lang=fr&activeSportId=1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace cSharpWebParserV04
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, List<List<string>>> result12 = Parsing12(url12: "https://parisportif.pmu.fr/");
        if (result12 != null)
        {
            foreach (var item12 in result12)
            {
                Console.WriteLine(&quot;-----------------------------------------&quot;);
                Console.WriteLine(item12.Key);
                Console.WriteLine(&quot;-----------------------------------------&quot;);
                item12.Value.ForEach(r =&gt; Console.WriteLine(string.Join(&quot;\t&quot;, r)));
                Console.WriteLine(&quot;-----------------------------------------\n&quot;);
            }
        }
        Console.ReadKey();
    }
    private static Dictionary&lt;string, List&lt;List&lt;string&gt;&gt;&gt; Parsing12(string url12)
    {
        try
        {
            Dictionary&lt;string, List&lt;List&lt;string&gt;&gt;&gt; result1 = new Dictionary&lt;string, List&lt;List&lt;string&gt;&gt;&gt;();
            using (HttpClientHandler hdl = new HttpClientHandler { AllowAutoRedirect = false, AutomaticDecompression = System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.None })
            {
                using (var clnt = new HttpClient(hdl))
                {
                    using (HttpResponseMessage resp = clnt.GetAsync(url12).Result)
                    {
                        if (resp.IsSuccessStatusCode)
                        {
                            var html = resp.Content.ReadAsStringAsync().Result;
                            if (!string.IsNullOrEmpty(html))
                            {
                                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                                doc.LoadHtml(html);
                                var tables = doc.DocumentNode.SelectNodes(&quot;.//div[@class='sb-event-list__main']//div[@class='sb-event-list__container']//div[@class]//&quot;);// ЗАМЕНИТЬ КЛАСС
                                if (tables != null &amp;&amp; tables.Count &gt; 0)
                                {
                                    foreach (var table in tables)
                                    {
                                        var titleNode = table.SelectSingleNode(&quot;.//div[@class='ng-star-inserted']&quot;);
                                        if (titleNode != null)
                                        {
                                            var tbl = table.SelectSingleNode(&quot;.//div[@class='ng-star-inserted']//table&quot;);
                                            if (tbl != null)
                                            {
                                                var rows = tbl.SelectNodes(&quot;.//ss-events-list-event&quot;);
                                                if (rows != null &amp;&amp; rows.Count &gt; 0)
                                                {
                                                    var res = new List&lt;List&lt;string&gt;&gt;();
                                                    foreach (var row in rows)
                                                    {
                                                        var cells = row.SelectNodes(&quot;.//span&quot;);
                                                        if (cells != null &amp;&amp; cells.Count &gt; 0)
                                                        {
                                                            res.Add(new List&lt;string&gt;(cells.Select(c =&gt; c.InnerText)));
                                                        }
                                                    }
                                                    result1[titleNode.InnerText] = res;
                                                }
                                            }
                                        }
                                    }
                                    return result1;
                                }
                                else
                                {
                                    Console.WriteLine(&quot;No tables&quot;);
                                }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex) { Console.WriteLine(ex.Message); }
        return null;
    }
}

}

  • 1
    Версия .NET какая? 46, 51, 54, 57, 63 строки - это где? К каким именно таблицам? В чём заключается задача? На сайте нет ничего из классов, указанных в вашем коде. Вы хоть видели HTML, который отдаёт сайт? Console.WriteLine(html); - там вообще нет таблиц. Почему пытаетесь искать в нём то, чего нет в принципе? Смотрите логи браузера, откуда берутся данные, HtmlAgilityPack не нужен здесь вообще https://i.stack.imgur.com/Y9LMa.png Нужно получить и распарсить JSON файлы. – aepot Mar 07 '24 at 13:23
  • 1
    https://ru.stackoverflow.com/a/924276/220553 – EvgeniyZ Mar 07 '24 at 13:53

0 Answers0