public void ScrapList(string html) { HtmlWeb web = new HtmlWeb(); List <ListSite> listSites = new List <ListSite>(); var htmlDoc = web.Load(html); try { foreach (HtmlNode link in htmlDoc.DocumentNode.SelectNodes("//div/div") .Where(x => x.GetAttributeValue("class", string.Empty) .Equals("product-box")) .ToList()) { ListSite element = new ListSite(); element.Link = link.SelectSingleNode("a").GetAttributeValue("href", string.Empty); element.Image = link.SelectSingleNode("a/div/img").GetAttributeValue("src", string.Empty).Insert(0, "http:"); element.Name = link.SelectSingleNode("a/div/img").GetAttributeValue("alt", string.Empty); element.Price = link.SelectSingleNode("a/div/div/div/meta").GetAttributeValue("content", string.Empty); listSites.Add(element); } Products = new ObservableCollection <ListSite>(listSites); } catch (Exception) { } }
public void ViewHistorySearch() { List <ListSite> historyProducts = new List <ListSite>(); using (ListSiteContext dbContext = new ListSiteContext()) { foreach (var col in dbContext.ListSites.ToList()) { ListSite element = new ListSite(); element.ListSiteID = col.ListSiteID; element.Image = col.Image; element.Link = col.Link; element.Name = col.Name; element.Price = col.Price; historyProducts.Add(element); } } Products = new ObservableCollection <ListSite>(historyProducts); }