Exemplo n.º 1
0
        public static IEnumerable <RankResultParseDto> ParseRankingSource(DataSourceRanking source, string nodeClassname)
        {
            var results = new List <RankResultParseDto>();
            var web     = new HtmlWeb();
            var htmlDoc = web.Load(source.Url);

            var htmlTables = ParseHtmlSplitTables(htmlDoc.ParsedText, nodeClassname);


            foreach (var table in htmlTables)
            {
                var htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(table);
                //Gives you all the TR
                var trs = htmlDocument.DocumentNode.Descendants("TR").ToArray();

                var takeCount          = (trs.Length - 2);
                var trsFiltered        = trs.Skip(2).Take(takeCount);
                var trDivisionDetail   = trs.First();
                var subDivisionDetails = trDivisionDetail.InnerText.Trim();

                foreach (var tr in trsFiltered)
                {
                    // Get All the TD's
                    var tds = tr.Descendants("TD").ToArray();


                    var rslt = new RankResultParseDto
                    {
                        Position         = int.Parse((tds[0].InnerText.Trim())),
                        TeamName         = tds[1].InnerText.Trim(),
                        GamesPlayed      = int.Parse(tds[2].InnerText.Trim()),
                        GamesWon         = int.Parse(tds[3].InnerText.Trim()),
                        GamesLost        = int.Parse(tds[5].InnerText.Trim()),
                        BasketsFor       = int.Parse(tds[6].InnerText.Trim()),
                        BasketsAganist   = int.Parse(tds[7].InnerText.Trim()),
                        PointsDifference = int.Parse(tds[8].InnerText.Trim()),
                        Points           = int.Parse(tds[10].InnerText.Trim())
                    };

                    results.Add(rslt);
                }
            }

            return(results);
        }
Exemplo n.º 2
0
 public async Task CreateRankingDataSourceAsync(DataSourceRanking dataSourceRanking)
 {
     _wpbDataContext.DataSourceRankings.Add(dataSourceRanking);
     await _wpbDataContext.SaveChangesAsync();
 }