private static void ConfigurationToJSON(ConsoleScrapperData scrapperData, String fileName = "") { try { string rawJson = JsonConvert.SerializeObject(scrapperData, Formatting.Indented); if (!String.IsNullOrEmpty(fileName) && File.Exists(fileName) && fileName.ToLower().EndsWith(".json")) { File.WriteAllText(fileName, rawJson); } else { string tmpfileName = AppDomain.CurrentDomain.BaseDirectory + "\\config.json"; File.WriteAllText(tmpfileName, rawJson); } } catch (Exception ex) { logger.Error(ex.ToString()); //should do something here. Console.WriteLine("\nUnable to write json configuration file, {0}!\n", fileName); } }
public override async Task <Product> RequestProduct(String Url) { Product product = new Product(); product.Url = Url; if (Url.ToLower().Contains("bhphotovideo.com")) { try { char[] charsToTrim = { ' ', '\n', '\t' }; IDocument productDoc = await this.GetWeb(Url); if (productDoc == null) { product.Valid = false; return(product); } String name = productDoc.QuerySelector(".js-main-product-name") != null?productDoc.QuerySelector(".js-main-product-name").TextContent. Trim(charsToTrim).Replace("\n", " ").Replace("\t", "") : String.Empty; product.Name = name; String price = productDoc.QuerySelector("span.ypYouPay") != null?productDoc.QuerySelector("span.ypYouPay").TextContent. Trim(charsToTrim) : String.Empty; product.Price = price; var availabilityNode = productDoc.QuerySelectorAll("span").Where(t => t.HasAttribute("data-selenium") && (t.GetAttribute("data-selenium"). Equals("inStock") || t.GetAttribute("data-selenium").Equals("notStock"))).FirstOrDefault(); String availability = availabilityNode != null?availabilityNode.GetAttribute("data-selenium") : String.Empty; product.Availability = availability.Equals("inStock")?"In-Stock":"Out-of-Stock"; product.Valid = true; } catch (Exception ex) { LoggerCin logger = new LoggerCin("C:\\Development\\ProductStatusNotifier\\Test\\bin\\Debug"); logger.Error(ex.ToString()); product.Valid = false; } } return(product); }
public override async Task <Product> RequestProduct(String Url) { Product product = new Product(); product.Url = Url; if (Url.ToLower().Contains("sabrepc.com")) { try { char[] charsToTrim = { ' ', '\n', '\t' }; IDocument productDoc = await this.GetWeb(Url); if (productDoc == null) { product.Valid = false; return(product); } String name = productDoc.QuerySelector("div.product-name") != null?productDoc.QuerySelector("div.product-name").FirstElementChild.TextContent. Trim(charsToTrim).Replace("\n", " ").Replace("\t", "").Trim() : String.Empty; product.Name = name; var priceNode = productDoc.QuerySelector("div.product-d").Children.Where(x => x.ClassName.Contains("integral")).FirstOrDefault(); String price = priceNode != null ? priceNode.TextContent : String.Empty; product.Price = price; var availabilityNode = productDoc.QuerySelectorAll("span").Where(n => n.ParentElement.ClassName.ToLower().Equals("availability in-stock")).FirstOrDefault(); string availability = availabilityNode != null ? availabilityNode.TextContent : String.Empty; product.Availability = availability.Equals("Out Of Stock") ? "Out-of-Stock" : "In-Stock"; product.Valid = true; } catch (Exception ex) { LoggerCin logger = new LoggerCin("C:\\Development\\ProductStatusNotifier\\Test\\bin\\Debug"); logger.Error(ex.ToString()); product.Valid = false; } } return(product); }
public override async Task <Product> RequestProduct(String Url) { Product product = new Product(); product.Url = Url; if (Url.ToLower().Contains("tigerdirect.com")) { try { char[] charsToTrim = { ' ', '\n', '\t' }; IDocument productDoc = await this.GetWeb(Url); String name = productDoc.QuerySelector("div.prodName") != null?productDoc.QuerySelector("div.prodName h1").TextContent. Trim(charsToTrim).Replace("\n", " ").Replace("\t", "") : String.Empty; product.Name = name; String price = productDoc.QuerySelector(".salePrice") != null?productDoc.QuerySelector("span.salePrice").TextContent. Trim(charsToTrim) : String.Empty; product.Price = price; String availability = productDoc.QuerySelectorAll(".prodMesg") != null?productDoc.QuerySelector(".prodMesg").TextContent.Trim(charsToTrim) : String.Empty; product.Availability = availability.ToLower().Contains("in stock") ? "In-Stock" : "Out-of-Stock"; product.Valid = true; } catch (Exception ex) { LoggerCin logger = new LoggerCin("C:\\Development\\ProductStatusNotifier\\Test\\bin\\Debug"); logger.Error(ex.ToString()); product.Valid = false; } } return(product); }