Esempio n. 1
0
        public IReadOnlyList <StudentSelection> Update()
        {
            var result = new List <StudentSelection>();

            using (var stream = _webDownloader.GetLoadStream(_uri))
            {
                var document = new HtmlDocument();
                document.Load(stream, true);

                var htmlNodes = document.DocumentNode.Descendants("tbody");
                var node      = htmlNodes.FirstOrDefault();
                if (node == null)
                {
                    throw new ArgumentException("Не найдено ни одной таблицы");
                }

                string lastSpec = null;
                foreach (var childNode in node.Descendants())
                {
                    if (childNode.Name == "strong")
                    {
                        TryFindSpecName(childNode.InnerText, ref lastSpec);
                    }

                    if (childNode.Name == "li")
                    {
                        if (lastSpec == null)
                        {
                            throw new ArgumentException("Список людей без предшествуещего имени спецкурса");
                        }

                        var pos = childNode.InnerText.IndexOf("--", StringComparison.Ordinal);
                        result.Add(new StudentSelection
                        {
                            Name           = childNode.InnerText.Substring(0, pos - 1),
                            Group          = childNode.InnerText.Substring(pos + 3, 5),
                            SpecCourseName = lastSpec
                        });
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
        private IReadOnlyCollection <LessonInfo> GetGroupLessons(string group)
        {
            var uri = $"{_baseUri}{group}";

            try
            {
                using (var stream = _downloader.GetLoadStream(uri))
                {
                    var document = new HtmlDocument();
                    document.Load(stream, true);
                    return(_parser.ParseTable(document, group));
                }
            }
            catch (Exception e)
            {
                Console.Out.WriteLine($"Проблема с группой {group}: {e.Message}");
                throw;
            }
        }