/// <summary> /// Scrapes a document for schedule /// </summary> /// <param name="scheduleDocument">Schedule document to be scraped</param> /// <returns>Scraped ScheduleModel</returns> public async Task <Schedule.Week> ScrapeSchedule(IDocument scheduleDocument) { IHtmlCollection <IElement> matchupContainers = scheduleDocument.HtmlDocument.QuerySelectorAll(".schedules-list .schedules-table"); Schedule.Week weekModel = new Schedule.Week(); foreach (var matchupContainer in matchupContainers) { Regex regex = new Regex("(?:<!--).*(-->)"); MatchCollection results = regex.Matches(matchupContainer.InnerHtml.ToString()); foreach (var result in results) { weekModel.RawElements.Add(result); Console.WriteLine(result.ToString()); } } weekModel.ScheduleDays = GetGameDays(weekModel.RawElements); foreach (Day scheduleDay in weekModel.ScheduleDays) { scheduleDay.Games = GetGames(scheduleDay); } return(weekModel); }
/// <summary> /// Scrapes the schedule for the given year and week /// </summary> /// <param name="scheduleDate">Schedule date from ScheduleDates dictionary</param> /// <param name="year">Schedule Year</param> /// <returns>Scraped SchedultModel</returns> public async Task <Schedule.Week> GetSchedule(string scheduleDate, int year) { Schedule.Week weekModel = new Schedule.Week(); IDocument scheduleDoc = await LoadSchedule(scheduleDate, year); weekModel = await ScrapeSchedule(scheduleDoc); return(weekModel); }
public static void Main(string[] args) { NFLScraper.NFLScraper nflScraper = new NFLScraper.NFLScraper(); NFLScraper.Schedule.Week weekModel = nflScraper.GetSchedule(NFLScraper.NFLScraper.ScheduleDates["REG1"], 2018).GetAwaiter().GetResult(); }