Beispiel #1
0
        private static IEnumerable <ProductDTO> ExtractProductFromHtml(HtmlDocument doc)
        {
            var node        = HtmlNodeHelper.GetFirstByNameAndClass(doc.DocumentNode.Descendants(), "ul", "srp-results srp-list clearfix");
            var descendants = node?.Descendants();

            if (descendants?.Any() != true)
            {
                return(Enumerable.Empty <ProductDTO>());
            }

            var lis = HtmlNodeHelper.GetAllByNameAndAttribute(descendants, "li", "class", "s-item");

            var products = new List <ProductDTO>();

            for (int i = 0; i < _IndexesCount && i < lis.Count(); i++)
            {
                var product = ExtractProductDetails(lis.ElementAt(i).Descendants());
                if (product != null)
                {
                    products.Add(product);
                }
            }

            return(products);
        }
Beispiel #2
0
        private static IEnumerable <ProductDTO> ExtractProductFromHtml(HtmlDocument doc)
        {
            var node = HtmlNodeHelper.GetFirstByNameAndClass(doc.DocumentNode.Descendants(), "div", "product-list grid");

            var descendants = node.Descendants();

            var divs = HtmlNodeHelper.GetAllByNameAndAttribute(descendants, "div", "class", "col-xs-6 col-lg-4 col-xl-3 product");

            var products = new List <ProductDTO>();

            for (int i = 0; i < _IndexesCount && i < divs.Count(); i++)
            {
                var product = ExtractProductDetails(divs.ElementAt(i).Descendants());
                if (product != null)
                {
                    products.Add(product);
                }
            }

            return(products);
        }