Пример #1
0
        public override List<IThreadedWebClientJob> Execute()
        {
            CQ dom = this.GetHtml();

            Sofa sofa = new Sofa();
            sofa.Url = this.GetUrl();
            sofa.Id = dom.Find("#pid").Attr("value");
            var price = dom.Find("em.product__price-now--amount").Text().Replace("£", "").Replace(",", "");
            double parsedPrice;
            if(double.TryParse(price, out parsedPrice)) {
                sofa.Price = parsedPrice;
            }
            sofa.Name = dom.Find("h1[itemprop=\"name\"]").Text();
            StringBuilder builder = new StringBuilder();
            foreach(var d in dom.Find(".product-information__bd").Find("p").Select(x => x.Cq().Text().Trim()))
            {
                builder.AppendLine(d);
            }
            foreach (var d in dom.Find(".product-information__bd").Find("li").Select(x => x.Cq().Text().Trim()))
            {
                builder.AppendLine(" * " + d);
            }
            sofa.Desc = builder.ToString();

            // Images
            foreach(var i in dom.Find(".product-gallery__grid").Find("img"))
            {
                sofa.Images.Add(i.Cq().Attr("src"));
            }

            // Size
            sofa.MesurmentImage = dom.Find("img.size-guide__img").Attr("src");
            foreach(var s in dom.Find(".size-guide__table").Find("tr").Select(x=>x.Cq().Find("td").Select(y=>y.Cq().Text()).ToList()))
            {
                if(s.Count >= 2) { 
                    sofa.Mesurments.Add(s[0], s[1]);
                }
            }

            // Fabricts
            foreach(var f in dom.Find("#swatches").Find("a.product-swatches__item").Select(x => x.Cq()))
            {
                Fabricts fab = new Fabricts();
                fab.Image = f.Find("img").Attr("src");
                fab.Name = f.Find("b.product-swatches__category").Text().Trim();
                fab.Url = "http://www.scs.co.uk" + f.Attr("data-url");
                sofa.Fabricts.Add(fab);
            }

            holder.Add(sofa);
            return this.ReturnNothing();
        }
        public override List<IThreadedWebClientJob> Execute()
        {
            CQ dom = this.GetHtml();
            var body = dom.Find(".Body_pnlContent");

            Sofa sofa = new Sofa();
            sofa.Url = this.GetUrl();
            sofa.Category = this.category;
            sofa.Name = dom.Find("h1").First().Text().Trim();
            
            sofa.Desc = dom.Find(".tabContent").First().Text().Trim();
            sofa.Desc = RegexHelper.Replace(@"([ ]+)", " ", sofa.Desc);
            sofa.Desc = RegexHelper.Replace(@"([\n]+)", "\n", sofa.Desc);
            var priceText = dom.Find("[itemprop=\"price\"]").Last().Text();
            double price;
            if (double.TryParse(priceText, out price))
            {
                sofa.Price = price;
            }

            // Images
            foreach (var img in dom.Find(".horzonProductCarousel").Find("img").Select(x=>x.Cq()))
            {
                sofa.Images.Add(img.Attr("src").Split('?').First());
            }
            
            // Fabricts
            var fabricts = dom.Find(".colorOptionContainer").Find("dd").Find("a").Select(x => x.Cq());
            foreach (var fabrict in fabricts)
            {
                var img = fabrict.Find("img");

                Fabricts fab = new Fabricts();
                fab.Url = "http://www.furniturevillage.co.uk" + fabrict.Attr("href");
                fab.Name = img.Attr("alt");
                fab.Image = img.Attr("src").Split('?').First();

                sofa.Fabricts.Add(fab);
            }

            // Mesurement
            foreach (var dd in dom.Find(".dimensionsLeft").Find("dd").Select(x=>x.Cq()))
            {
                var inner = dd[0].InnerText.Trim();
                var value = dd.Find("b").Text().Trim();
                sofa.Mesurments.Add(inner, value);
            }

            this.holder.Add(sofa);
            return this.ReturnNothing();
        }
        public override List<IThreadedWebClientJob> Execute()
        {
            var newJobs = new List<IThreadedWebClientJob>();
            var products = RegexHelper.MatchAll(@"Products\[(.*?);", this.GetHtml());
            foreach (var product in products)
            {
                try
                {
                    string imageTemplate =
                    "http://steinhoffukretailltd.scene7.com/is/image/SteinhoffUKRetailLtd/{0}_{1}_{2}_IS_0";
                    var id = RegexHelper.Match(@"(\d+)\'\]\s+=", product);
                    var jsonText = RegexHelper.Match(@"\d+\'\]\s+=(.+);;", product + ";;");
                    var json = JsonConvert.DeserializeObject<dynamic>(jsonText);

                    string sku = json.sku;

                    foreach (var _variant in json.variants)
                    {
                        var variant = _variant.First;

                        Sofa sofa = new Sofa();
                        sofa.Id = id;
                        sofa.Url = this.GetUrl();
                        sofa.Name = variant.gtm["data-gtm-product-name"];
                        sofa.Category = variant.gtm["data-gtm-product-category"];
                        sofa.Brand = variant.gtm["data-gtm-product-brand"];
                        double price;
                        if (double.TryParse(variant.prices.price.value.ToString(), out price))
                        {
                            sofa.Price = price;
                        }

                        string default_trim = variant.default_trim;
                        string default_color = variant.default_cover_colour;
                        sofa.Images.Add(string.Format(imageTemplate, sku, default_color, default_trim));

                        foreach (var _color in variant.cover_colours)
                        {
                            var color = _color.First;
                            Fabricts fab = new Fabricts();
                            fab.Name = color.description;
                            fab.Fabric = color.fabric;
                            fab.Image = string.Format(imageTemplate, sku, color.code, default_trim);
                            sofa.Fabricts.Add(fab);
                        }
                        
                        newJobs.Add(new HarveysFurnitureSofaGetDetails(this.sofaHolder, sofa, variant.variant_id.ToString(), id));
                    }
                }
                catch (Exception exp)
                {
                    logger.Error("Collection product failed.", exp);
                }
            }

            return newJobs;
        }
        public HarveysFurnitureSofaGetDimensions(HolderBase<Sofa> sofaHolder, Sofa sofa, string variantId, string productId)
        {
            this.holder = sofaHolder;
            this.sofa = sofa;

            this.SetUrl(string.Format(
                "http://www.harveysfurniture.co.uk/collection/tab/dimensions?variant_id={0}&product_id={1}&is_bundle=false",
                variantId, productId));
        }