public async Task <List <RozkladLesson>[]> GetTimetable() { try { await InitRequest(); } catch (Exception e) { } //Group selection Timetable.AddNew("ctl00$MainContent$ctl00$txtboxGroup", Group); message = new HttpRequestMessage(); SetHeaders(); message.Headers.AddIfNotExists("Referer", "http://rozklad.kpi.ua/Schedules/ScheduleGroupSelection.aspx"); message.Method = HttpMethod.Post; message.RequestUri = new Uri("http://rozklad.kpi.ua/Schedules/ScheduleGroupSelection.aspx"); Timetable.AddIfNotExists("ctl00$MainContent$ctl00$btnShowSchedule", "Розклад занять"); message.Content = new FormUrlEncodedContent(Timetable); var response = await client.SendAsync(message).Result.Content.ReadAsStringAsync(); var document = new HtmlDocument(); document.LoadHtml(response); var result = new List <RozkladLesson> [2]; result[0] = ParseTable(document.DocumentNode.SelectSingleNode($@"//table[@id='{FirstWeek}']"), true); result[1] = ParseTable(document.DocumentNode.SelectSingleNode($@"//table[@id='{SecondWeek}']"), false); foreach (var item in result[0]) { if (!Teachers.Exists(t => t.Name == item.Teacher.Name)) { Teachers.Add(item.Teacher); } if (!Subjects.Exists(t => t.Title == item.Subject.Title)) { Subjects.Add(item.Subject); } } foreach (var item in result[1]) { if (!Teachers.Exists(t => t.Name == item.Teacher.Name)) { Teachers.Add(item.Teacher); } if (!Subjects.Exists(t => t.Title == item.Subject.Title)) { Subjects.Add(item.Subject); } } RozkladTimeTable = result; return(result); }
private async Task InitRequest() { SetHeaders(); message.Headers.AddIfNotExists("Referer", "http://rozklad.kpi.ua"); message.Method = HttpMethod.Get; message.RequestUri = new Uri("http://rozklad.kpi.ua/Schedules/ScheduleGroupSelection.aspx"); var document = new HtmlDocument(); var html = await client.SendAsync(message).Result.Content.ReadAsStringAsync(); document.LoadHtml(html); var inputs = document.DocumentNode.SelectNodes(@"//input[@type='hidden']"); foreach (var item in inputs) { Timetable.AddIfNotExists(item.Attributes["name"].Value, item.Attributes["value"].Value); } }