Ejemplo n.º 1
0
        static public List <ParsedProduct> GetParsedProduct(string HTML, IProductXPath parsedProduct)
        {
            List <ParsedProduct> parsedProductList = new List <ParsedProduct>();
            var document = new HtmlDocument();

            document.LoadHtml(HTML);
            string title = null;

            // parse product title
            HtmlNodeCollection titleNodes = document.DocumentNode.SelectNodes(parsedProduct.TitleXPath); //".//h3[@class='content-product__name-heading']/a"

            foreach (HtmlNode titleProd in titleNodes)
            {
                title = titleProd.GetAttributeValue("title", null);
                ParsedProduct resultProduct = new ParsedProduct {
                    Title = title
                };
                parsedProductList.Add(resultProduct);
            }


            // parse product Price
            HtmlNodeCollection prices = document.DocumentNode.SelectNodes(parsedProduct.PriseXPath); //  //span[@class='wc-price-sale']//span[@class='wc-price-number']
            int j = 0;

            int n = 0;

            foreach (HtmlNode price in prices)
            {
                if (price != null)
                {
                    string decodedString = price.InnerText.Replace("&nbsp; &#8372;", " грн."); // ₴InnerText = "\n            от 2 619&nbsp; &#8372;        "
                    decodedString = decodedString.Replace("  ", string.Empty);
                    decodedString = decodedString.Replace("\n", string.Empty);
                    parsedProductList.ElementAt(n++).Price = decodedString;
                }
            }


            // parce product image .//li//div[@class='content-product__thumb']//a//img
            HtmlNodeCollection imgs = document.DocumentNode.SelectNodes(parsedProduct.ImageXPath); //content - product__thumb
            int k = 0;

            foreach (HtmlNode imgUrl in imgs)
            {
                string   urlImage = imgUrl.Attributes["data-srcset"].Value;// ("DeEntitizeValue", null);// DeEntitizeValue = "https://badminton.ua/wp-content/themes/badminton/public/img/logo/logo-icon.png"
                string[] arr_Url  = urlImage.Split(' ');
                urlImage = arr_Url[0];
                if (urlImage != null)
                {
                    Image  imageCurProd     = DownloadImageByUrl(urlImage);
                    byte[] bytesArrForImage = imageToByteArray(imageCurProd);
                    parsedProductList.ElementAt(k++).ImageBytes = bytesArrForImage;
                }
            }

            return(parsedProductList);
        }
Ejemplo n.º 2
0
        public ActionResult GetParsedProduct(ViewModelSiteProduct site)
        {
            ParsedProduct pp = new ParsedProduct()
            {
                Id = 1, Title = "testTitle", Price = "5", Description = "testDesc"
            };
            List <ParsedProduct> listPP = new List <ParsedProduct>();

            listPP.Add(pp);
            return(View(listPP));
        }
Ejemplo n.º 3
0
        protected override void Seed(ProductContext context)
        {
            Site site1 = new Site()
            {
                Name = "badminton.ua", Url = "https://badminton.ua/product/category/krossovki-dlya-badmintona/krossovki-fz-forza/"
            };
            Site site2 = new Site()
            {
                Name = "allo.ua", Url = "https://allo.ua/ru/products/mobile/proizvoditel-xiaomi/"
            };
            Site site3 = new Site()
            {
                Name = "rozetka.ua", Url = "https://allo.ua/ru/products/mobile/proizvoditel-xiaomi/"
            };

            context.Site.Add(site1);
            context.Site.Add(site2);
            context.Site.Add(site3);
            context.SaveChanges();

            Product product1 = new Product()
            {
                ProdName = "badminton.ua/shoes", Siteid = 1
            };
            Product product2 = new Product()
            {
                ProdName = "badminton.ua/rackets", Siteid = 1
            };
            Product product3 = new Product()
            {
                ProdName = "allo.ua/mobile", Siteid = 2
            };
            Product product4 = new Product()
            {
                ProdName = "allo.ua/pc", Siteid = 2
            };

            context.Product.Add(product1);
            context.Product.Add(product2);
            context.Product.Add(product3);
            context.Product.Add(product4);

            context.SaveChanges();

            ParsedProduct pp = new ParsedProduct()
            {
                Description = "test1", Price = "test", Title = "testPorduct"
            };

            context.ParsedProduct.Add(pp);
            context.SaveChanges();
        }
Ejemplo n.º 4
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ParsedProduct product = dbContext.ParsedProduct.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            return(View(product));
        }
Ejemplo n.º 5
0
 public static bool IsParsedProductEqualToProduct(ParsedProduct parsedProduct, Product product)
 => parsedProduct.Name == product.Name &&
 parsedProduct.SubCategory == product.SubCategory &&
 parsedProduct.Category == product.Category &&
 parsedProduct.ShopType == product.ShopType;
Ejemplo n.º 6
0
 static public void SaveProductToDB(ParsedProduct product, ProductContext context)
 {
     context.ParsedProduct.Add(product);
 }