コード例 #1
0
        internal static Task <GameResult[]> ExtractLeagueGameResultsAsync(DomResultItem item, CancellationToken ct)
        {
            return(Task.Run(() =>
            {
                var html = new HtmlDocument();
                html.LoadHtml(item.Content);

                var resultsTable = html.DocumentNode.SelectSingleNode("//table[@id='mbt-v2-schedule-table']");
                if (resultsTable != null)
                {
                    var result = ExtractFixturesOrResults <GameResult>(resultsTable, includeResults: true, ct);
                    return result;
                }
                else
                {
                    var container = html.DocumentNode.SelectSingleNode("//div[@id='33-303-container']");
                    if (container.Element("p")?.InnerText.StartsWith("Nobena tekma ne ustreza vašim kriterijem.") ?? false)
                    {
                        return new GameResult[0];
                    }
                    else
                    {
                        throw new Exception("No results table");
                    }
                }
            }));
        }
コード例 #2
0
        internal static Task <LeagueOverview> ExtractStandingsAndFixturesAsync(DomResultItem item, bool areStandingRequired, CancellationToken ct)
        {
            return(Task.Run(() =>
            {
                var html = new HtmlDocument();
                html.LoadHtml(item.Content);

                var standings = GetStandings(html, areStandingRequired, ct);
                var fixturesTable = html.DocumentNode.SelectSingleNode("//table[@id='mbt-v2-schedule-table']");
                GameFixture[] fixtures;
                // when there are no fixtures, pages shows only results
                if (IsFixturesTabActive(html))
                {
                    fixtures = ExtractFixturesOrResults <GameFixture>(fixturesTable, includeResults: false, ct);
                }
                else
                {
                    fixtures = new GameFixture[0];
                }
                return new LeagueOverview(
                    standings: standings,
                    fixtures: fixtures.Where(f => f != null).ToArray(),
                    results: null
                    );
            }));
        }
コード例 #3
0
        internal static Task <Team> GetTeamDataAsync(DomResultItem domItem, CancellationToken ct)
        {
            return(Task.Run(() =>
            {
                const string infoValueSelector = "span[@class='mbt-v2-team-full-widget-main-info-value']";
                var html = new HtmlDocument();
                html.LoadHtml(domItem.Content);
                var root = html.DocumentNode.SelectSingleNode("//div[@id='33-200-qualizer-1']");
                var frame = html.DocumentNode.SelectSingleNode("(//div[@class='mbt-v2-col mbt-v2-col-6'])[2]");

                string name = null;
                string shortName = null;
                string city = null;
                string coach = null;
                Arena arena = null;

                foreach (var node in frame.SelectNodes("div[@class='mbt-v2-team-full-widget-main-info']"))
                {
                    var header = node.SelectSingleNode("span[@class='mbt-v2-team-full-widget-main-info-attribute']").InnerText;
                    if (header.Contains("Mesto:"))
                    {
                        city = node.SelectSingleNode(infoValueSelector).InnerText;
                    }
                    else if (header.Contains("Kratko ime:"))
                    {
                        shortName = node.SelectSingleNode(infoValueSelector).InnerText;
                    }
                    else if (header.Contains("Klub:"))
                    {
                        name = node.SelectSingleNode(infoValueSelector).InnerText;
                    }
                    else if (header.Contains("Trener:"))
                    {
                        coach = node.SelectSingleNode(infoValueSelector).InnerText;
                    }
                    else if (header.Contains("Dvorana:"))
                    {
                        var valueNode = node.SelectSingleNode(infoValueSelector);
                        var a = valueNode.SelectSingleNode("a");
                        int arenaId = int.Parse(a.GetAttributeValue("arena_id", null));
                        arena = new Arena(arenaId, a.InnerText, HttpUtility.HtmlDecode(a.GetAttributeValue("href", null)));
                    }
                }

                return new Team(
                    name,
                    shortName,
                    city,
                    arena,
                    coach,
                    players: null,
                    lastResults: null,
                    fixtures: null
                    );
            }));
        }
コード例 #4
0
 internal static Task <TeamGameResult[]> GetLastTeamResultsAsync(DomResultItem domItem, CancellationToken ct)
 {
     return(Task.Run(() =>
     {
         var html = new HtmlDocument();
         html.LoadHtml(domItem.Content);
         var rows = html.DocumentNode.SelectNodes("//table[@id='mbt-v2-team-home-results-table']/tbody/tr");
         var result = rows.Select(r => GetTeamGameResult(r)).ToArray();
         return result;
     }));
 }