예제 #1
0
        public void ProductsAreNotNull(string url)
        {
            FoxtrotParser rpd    = new FoxtrotParser();
            List <String> proxys = new ProxyBuilder().GenerateProxy().Build();

            Assert.NotNull(rpd.GetProduct(url, ref proxys));
        }
예제 #2
0
        private Product CreateInstanseOfProduct(IElement div, string url)
        {
            Product product = new Product();

            try
            {
                FoxtrotParser fp = new FoxtrotParser();
                var           elementDetailLink = div.GetElementsByClassName("detail-link")[0];
                string        urlForPage        = elementDetailLink.GetAttribute("href");
                var           img = elementDetailLink.GetElementsByTagName("img")[0];
                product = fp.GetProduct(urlForPage, ref proxyList);

                product.Name = div.GetAttribute("data-title");
                var massForIndex = product.Name.Split("(");
                if (massForIndex.Length > 1)
                {
                    product.Index = product.Name.Split("(")[1].Split(")")[0];
                }


                var     price          = div.GetElementsByClassName("price")[0];
                var     priceWrapper   = price.GetElementsByClassName("price__wrapper")[0];
                var     price_relevant = priceWrapper.GetElementsByClassName("price__relevant")[0];
                decimal currentPrice   = getPriceFromNumb(price_relevant);
                var     discontWrapper = price.GetElementsByClassName("price__not-relevant");

                if (discontWrapper.Length > 0)
                {
                    decimal oldPrice = getPriceFromNumb(discontWrapper[0]);
                    product.LastPrice = new List <Price>()
                    {
                        new Price(currentPrice, oldPrice,
                                  new Company("Foxtrot", url))
                        {
                            IsDiscont = true, Discont = Math.Truncate(
                                (1 -
                                 (currentPrice / oldPrice))
                                * 100)
                        }
                    };
                }
                else
                {
                    product.LastPrice = new List <Price>()
                    {
                        new Price(
                            currentPrice,
                            new Company("Foxtrot", url))
                        {
                            IsDiscont = false
                        }
                    };
                }
                return(product);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }