Example #1
0
        public ArborioModel ParseData(IHtmlDocument document)
        {
            var recipe       = document.QuerySelector("#mainWrapper");
            var arborioModel = new ArborioModel();

            if (recipe != null)
            {
                var service = new ParserServise();
                service.InitCollection(arborioModel);
                var recipeName = recipe.QuerySelector(".detailed").TextContent;
                arborioModel.Name = recipeName;

                var descriptions = recipe.QuerySelector("[itemprop=recipeInstructions]");
                if (descriptions != null)
                {
                    var descriptinfo = descriptions.QuerySelectorAll("div").Where(
                        item => item.ClassName == "detailed_step_description_big");
                    foreach (var item in descriptinfo)
                    {
                        arborioModel.Description += item.TextContent + "\n";
                    }
                }

                var imghref = recipe.QuerySelector(".bigImgBox > a:nth-child(1) > img:nth-child(1)").GetAttribute("src");
                if (imghref != null)
                {
                    arborioModel.ImageHref = imghref;
                }
                var consist = document.QuerySelector(".ingredients_wrapper");

                var productsIinfo = consist.QuerySelectorAll("li")
                                    .Where(item => item.ParentElement.ClassName != null &&
                                           item.ParentElement.ClassName.Contains("detailed_ingredients")
                                           );

                var productsNameList  = new List <string>();
                var productsUnitsList = new List <string>();

                for (int i = 0; i < productsIinfo.Count(); i++)
                {
                    var product = productsIinfo.ElementAt(i).GetAttribute("rel");
                    productsNameList.Add(product);

                    var number       = productsIinfo.ElementAt(i).TextContent.Replace("—", "");
                    var resultNumber = number.Replace(product, "");
                    resultNumber.TrimStart();
                    productsUnitsList.Add(resultNumber);
                }


                arborioModel.Number   = productsUnitsList;
                arborioModel.Products = productsNameList;
            }
            return(arborioModel);
        }
Example #2
0
        public ArborioModel ParseData(IHtmlDocument document)
        {
            var recipe       = document.QuerySelector(".main-content");
            var arborioModel = new ArborioModel();

            if (recipe != null)
            {
                var service = new ParserServise();
                service.InitCollection(arborioModel);
                var descriptions = recipe.QuerySelector(".recipe__steps");
                if (descriptions != null)
                {
                    var descriptinfo = descriptions.QuerySelectorAll("li").Where(
                        item => item.ClassName.Contains("instruction"));
                    foreach (var item in descriptinfo)
                    {
                        arborioModel.Description += item.QuerySelector(".instruction__description").TextContent;
                    }
                }
                var consist    = document.QuerySelector(".ingredients-list__content");
                var ingredient = consist.QuerySelectorAll("p")
                                 .Where(item => item.ParentElement.ClassName != null &&
                                        item.ParentElement.ClassName.Contains("ingredients-list__content") &&
                                        item.ClassName != null &&
                                        item.ClassName.Contains("ingredients-list__content-item content-item js-cart-ingredients"));
                List <JObject> ingredientsJson = new List <JObject>();
                foreach (var item in ingredient)
                {
                    var ds      = item.GetAttribute("data-ingredient-object");
                    var objects = JObject.Parse(ds);
                    ingredientsJson.Add(objects);
                }
                var productsNames  = new List <string>();
                var productsAmount = new List <string>();
                foreach (JObject item in ingredientsJson)
                {
                    productsNames.Add((string)item["name"]);
                    productsAmount.Add((string)item["amount"]);
                }
                arborioModel.Number   = productsAmount;
                arborioModel.Products = productsNames;
                arborioModel.Name     = recipe.QuerySelector(".recipe__name").TextContent + "\n";
                arborioModel.Units    = productsAmount;
            }
            return(arborioModel);
        }