private void LoadGamesPerDivision(BrowserSession b, KeyValuePair<long, string> page) { try { var teams = GetTeams(1, page.Key); int take = 1; take = take + teams.Count / 2; if (teams.Count % 2 > 0) take++; var doc = b.GetDoc(page.Value); //Table => Games table var table = doc.DocumentNode.Descendants("table") .FirstOrDefault( t => t.Attributes.Contains("class") && t.Attributes["class"].Value.Contains("clubentrees")); if (table != null) { using (var context = new ScoresEntities()) { int skip = 1; var rows = table.Descendants("tr").Skip(skip).Take(take).ToList(); while (rows.Any()) { var dateRow = rows[0]; DateTime? date = ProcessDateRow(dateRow); if (date.HasValue) { foreach (var row in rows.Skip(1)) { Trace.WriteLine(row.InnerText); games game = ProcessGameRow(row, date.Value, teams, context, page); if (game != null && game.GameId <= 0) context.games.Add(game); } } Trace.WriteLine("----------"); skip = skip + take + 1; rows = table.Descendants("tr").Skip(skip).Take(take + 1).ToList(); } context.SaveChanges(); } } else Trace.WriteLine("---WRONG---"); } catch (Exception ex) { Trace.WriteLine(string.Format("There was an error fetching division {0}", page.Key)); throw; } }
public Fetcher() { pages = new Dictionary<long, string> { {1, "http://www.rugby.be/new/competition.cfm?div_id=10113"}, {2, "http://www.rugby.be/new/competition.cfm?div_id=10122"}, {3, "http://www.rugby.be/new/competition.cfm?div_id=10133"}, {4, "http://www.rugby.be/new/competition.cfm?div_id=10142"}, {5, "http://www.rugby.be/new/competition.cfm?div_id=10157"}, {6, "http://www.rugby.be/new/competition.cfm?div_id=10114"} }; browserSession = new BrowserSession(); //Force a first load to the correct season, calls after this will go to the correct page browserSession.GetDoc("http://www.rugby.be/new/competition.cfm?p_year=12"); }