private async Task NgKCralerAsync() { try { //the url of the page we want to test var url = "https://www.nguyenkim.com/dien-thoai-di-dong-apple-iphone/"; var httpClient = new HttpClient(); var htmlDocument = new HtmlDocument(); var html = await httpClient.GetStringAsync(url); htmlDocument.LoadHtml(html); // a list to add all the list of cars and the various prices if (crawledList == null) { crawledList = new List<CrawledItem>(); } //var cars = new List<Car>(); //var divs = htmlDocument.DocumentNode.Descendants("ul").FirstOrDefault().Descendants("li").ToList(); var divs = htmlDocument.DocumentNode.SelectNodes(@"//a[@class='nk-link-product']"); foreach (var div in divs) { var modelItem = div.Descendants("h6").FirstOrDefault().Descendants("a").FirstOrDefault(); string model = (modelItem == null) ? string.Empty : modelItem.InnerText; var priceItem = div.Descendants("span").Where(o => o.GetAttributeValue("class", "").Equals("price")).FirstOrDefault(); string price = priceItem.InnerText; string link = div.GetAttributeValue("href", ""); var imageItem = div.Descendants("div").Where(o => o.GetAttributeValue("class", "").Equals("product-image")).FirstOrDefault(); string image = imageItem.Descendants("img").FirstOrDefault().GetAttributeValue("src", ""); if (image == "") { image = imageItem.Descendants("img").FirstOrDefault().GetAttributeValue("data-src", ""); } var car = new CrawledItem(model, price, link, image); if (!string.IsNullOrEmpty(car.Model)) { crawledList.Add(car); } } Console.WriteLine("NgKCralerAsync done"); } catch (Exception) { } }
private async Task FPTSCralerAsync() { try { //the url of the page we want to test var url = "https://fptshop.com.vn/dien-thoai/apple-iphone"; var httpClient = new HttpClient(); var htmlDocument = new HtmlDocument(); var html = await httpClient.GetStringAsync(url); htmlDocument.LoadHtml(html); // a list to add all the list of cars and the various prices if (crawledList == null) { crawledList = new List<CrawledItem>(); } //var cars = new List<Car>(); //var divs = htmlDocument.DocumentNode.Descendants("ul").FirstOrDefault().Descendants("li").ToList(); var divs = htmlDocument.DocumentNode.SelectNodes(@"//div[@class='fs-lpil']"); foreach (var div in divs) { var modelItem = div.Descendants("h3").FirstOrDefault().Descendants("a").FirstOrDefault(); string model = (modelItem == null) ? string.Empty : modelItem.InnerText; var priceItem = div.Descendants("div").Where(o => o.GetAttributeValue("class", "").Equals("fs-lpil-price")).FirstOrDefault(); string price = priceItem.Descendants("p").FirstOrDefault().InnerText; string link = "https://fptshop.com.vn" + div.Descendants("a").Where(o => o.GetAttributeValue("class", "").Equals("fs-lpil-img")).FirstOrDefault().GetAttributeValue("href", ""); var imageItem = div.Descendants("img").Where(o => o.GetAttributeValue("class", "").Equals("lazy")).FirstOrDefault(); string image = imageItem.GetAttributeValue("data-original", ""); var item = new CrawledItem(model, price, link, image); if (!string.IsNullOrEmpty(item.Model)) { crawledList.Add(item); } } Console.WriteLine("FPTSCralerAsync done"); } catch (Exception) { } }
private async Task TikiCralerAsync() { try { //the url of the page we want to test var url = "https://tiki.vn/dien-thoai-smartphone/c1795/apple"; var httpClient = new HttpClient(); var htmlDocument = new HtmlDocument(); var html = await httpClient.GetStringAsync(url); htmlDocument.LoadHtml(html); // a list to add all the list of cars and the various prices if (crawledList == null) { crawledList = new List<CrawledItem>(); } //var cars = new List<Car>(); //var divs = htmlDocument.DocumentNode.Descendants("ul").FirstOrDefault().Descendants("li").ToList(); var divs = htmlDocument.DocumentNode.SelectNodes(@"//div[@class='product-item ']"); foreach (var div in divs) { var modelItem = div.Descendants("h3").FirstOrDefault().Descendants("a").FirstOrDefault(); string model = (modelItem == null) ? string.Empty : modelItem.InnerText; var priceItem = div.Descendants("p").Where(o => o.GetAttributeValue("class", "").Equals("fs-ctpri")).FirstOrDefault(); string price = priceItem.InnerText.Split(new string[1] { "Giá chỉ " }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); string link = div.GetAttributeValue("href", ""); var imageItem = div.Descendants("img").FirstOrDefault(); string image = "https://fstudiobyfpt.com.vn" + imageItem.GetAttributeValue("src", ""); var item = new CrawledItem(model, price, link, image); if (!string.IsNullOrEmpty(item.Model)) { crawledList.Add(item); } } Console.WriteLine("TikiCralerAsync done"); } catch (Exception) { } }
private async Task VTSCralerAsync() { try { //the url of the page we want to test var url = "https://viettelstore.vn/iphone"; var httpClient = new HttpClient(); var htmlDocument = new HtmlDocument(); var html = await httpClient.GetStringAsync(url); htmlDocument.LoadHtml(html); // a list to add all the list of cars and the various prices if (crawledList == null) { crawledList = new List<CrawledItem>(); } var divs = htmlDocument.DocumentNode.SelectNodes(@"//selection[@class='item ProductList3Col_item']"); foreach (var div in divs) { var modelItem = div.Descendants("h2").FirstOrDefault(); string model = (modelItem == null) ? string.Empty : modelItem.InnerText; var priceItem = div.Descendants("span").Where(o => o.GetAttributeValue("class", "").Equals("price")).FirstOrDefault(); string price = priceItem.InnerText; string link = div.GetAttributeValue("href", ""); var imageItem = div.Descendants("img").Where(o => o.GetAttributeValue("id", "").Equals("imgSeo_2")).FirstOrDefault(); string image = imageItem.GetAttributeValue("src", ""); var item = new CrawledItem(model, price, link, image); if (!string.IsNullOrEmpty(item.Model)) { crawledList.Add(item); } } Console.WriteLine("VTSCralerAsync done"); } catch (Exception) { } }