public CatalogNodeViewModel(Catalog catalog) { CurrentEntity = catalog; _articlesObservableList = new ObservableCollection<ArticleViewModel>(); ArticlesCollectionView = new ListCollectionView(_articlesObservableList); }
private async Task<List<Catalog>> ExtractCatalogsFromWebPage(string url) { List<Catalog> reusltCatalogs = new List<Catalog>(); var uri = new Uri(url); var browser1 = new ScrapingBrowser(); browser1.Encoding = Encoding.UTF8; var html1 = browser1.DownloadString(uri); var doc = new HtmlDocument(); doc.LoadHtml(html1); var html = doc.DocumentNode; foreach (var script in doc.DocumentNode.Descendants("script").ToArray()) { script.Remove(); } foreach (var style in doc.DocumentNode.Descendants("style").ToArray()) { style.Remove(); } foreach (var comment in doc.DocumentNode.SelectNodes("//comment()").ToArray()) { comment.Remove(); } var days = html.CssSelect("div.day"); if (!days.Any()) { days = html.CssSelect("div#container >div#wrapper >div#content"); } foreach (var day in days) { var catalog = new Catalog(); catalog.IsChecked = true; var title = day.CssSelect("div.dayTitle").FirstOrDefault(); if(title!=null) { catalog.Title = title.InnerText.ClearNotWords(); var atricles = day.CssSelect("div.postTitle"); foreach (var atricle in atricles) { var article = new Article(); article.Title = atricle.InnerText.ClearNotWords(); var articleTitleEl = atricle.CssSelect("a.postTitle2"); article.URL = articleTitleEl.First().Attributes["href"].Value; catalog.Articles.Add(article); } } else { catalog.Title = "CataLog"+DateTime.Now.ToShortTimeString(); var atricles = day.CssSelect("div.post"); foreach (var atricle in atricles) { var article = new Article(); var articleTitleEl = atricle.CssSelect("a.PostTitle"); article.Title = articleTitleEl.First().InnerText.ClearNotWords(); article.URL = articleTitleEl.First().Attributes["href"].Value; catalog.Articles.Add(article); } } reusltCatalogs.Add(catalog); } return reusltCatalogs; }