Example #1
0
        static void ParsePage(String link, Category category)
        {
            HtmlDocument page = new HtmlDocument();
            page.LoadHtml(new WebClient().DownloadString(link));

            HtmlNodeCollection recipes = page.DocumentNode.SelectNodes("//div[@class='lst']//ul//li//a");

            foreach (var recipe in recipes)
            {
                ParseRecipe(recipe.Attributes["href"].Value, category);
            }
        }
Example #2
0
        static void ParseRecipe(String link, Category category)
        {
            HtmlDocument recipePage = new HtmlDocument();
            recipePage.LoadHtml(new WebClient().DownloadString(link));

            Recipe recipe;
       
            String   name      = recipePage.DocumentNode.SelectSingleNode("//head//title").InnerText;
            HtmlNode secondary = recipePage.DocumentNode.SelectSingleNode("//div[@class='c8 ingredients']//h3"),
                     ul;
            
            if (!File.Exists(Helper.RecipePath(category.Name, name)))
            {
                using (StreamWriter sw = new StreamWriter(Helper.RecipePath(category.Name, name)))
                {
                    recipe = new Recipe(name, secondary == null ? "" : Helper.EscapeHTML(secondary.InnerText));

                    ul = recipePage.DocumentNode.SelectSingleNode("//div[@class='c8 ingredients']//ul[1]");

                    foreach (var li in ul.ChildNodes)
                    {
                        recipe.AddIngredient(Helper.EscapeHTML(li.InnerText));
                    }

                    if (recipe.Secondary != "")
                    {
                        ul = recipePage.DocumentNode.SelectSingleNode("//div[@class='c8 ingredients']//ul[2]");

                        if (ul != null)
                        {
                            foreach (var li in ul.ChildNodes)
                            {
                                recipe.AddAdditional(Helper.EscapeHTML(li.InnerText));
                            }
                        }
                    }

                    ul = recipePage.DocumentNode.SelectSingleNode("//div[@class='stepbystep e-instructions']");

                    foreach (var p in ul.ChildNodes)
                    {
                        recipe.AddStep(Helper.EscapeHTML(p.InnerText));
                    }

                    sw.Write(recipe);
                }
            }
            else
            {
                return;
            }

            Console.WriteLine("\t{0}", link);
        }