private BusinessObjects.Recipe ConvertIntoRecipe(string doc) { BusinessObjects.Recipe re = new BusinessObjects.Recipe(); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(doc); HtmlNode titleNode = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='headerItem']/section/header/h1"); re.Title = titleNode.InnerText; HtmlNode mainIngrNode = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='headerItem']/section/header/p"); re.MainIngredient = mainIngrNode.InnerText.Remove(0, "ingrediente principal : ".Length - 1); HtmlNode categoryNode = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='headerItem']/section/header/h3"); re.Category = categoryNode.InnerText; HtmlNode portNode = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='mainContent']/div/section/div/div[1]/h5"); re.Portions = ExtractForksNumber(portNode); var authorNode = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='headerItem']/section/header/h2"); re.Author = authorNode.InnerText.Remove(0, "por:".Length).Trim(); var imgNode = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='headerItem']/section/figure/img"); if (imgNode.Attributes.Contains("src")) re.ImageUrl = imgNode.Attributes["src"].Value; re.Ingridients = ProcessIngredients(htmlDoc); re.Procedure = ProcessProcedure(htmlDoc); HandleAlarms(re.Procedure, ref re); return re; }
private BusinessObjects.Recipe PreprocessRecipe(HtmlNode recetaNode) { string title = recetaNode.SelectSingleNode("article").SelectSingleNode("a").SelectSingleNode("header").SelectSingleNode("h1").InnerText; string author = recetaNode.SelectSingleNode("article").SelectSingleNode("a").SelectSingleNode("header").SelectSingleNode("h2").InnerText; HtmlNode anchor = recetaNode.SelectSingleNode("article").SelectSingleNode("a"); HtmlNode imgNode = anchor.SelectSingleNode("figure").SelectSingleNode("img"); string image = string.Empty; if (imgNode != null && imgNode.Attributes.Contains("src")) image = imgNode.Attributes["src"].Value; string link = string.Empty; if (anchor != null && anchor.Attributes.Contains("href")) link = anchor.Attributes["href"].Value; var item = new BusinessObjects.Recipe { Author = author.Replace("Por: ", string.Empty), Title = title, ImageUrl = image, LinkUrl = link }; DateTime now = DateTime.Now; Debug.WriteLine("----> Translate Started at {0}", now); TranslateRecipeMicrosoft(item); TimeSpan span = DateTime.Now.Subtract(now); Debug.WriteLine("----> Translate Time Elapsed {0}", span.ToString()); return item; }
private BusinessObjects.Recipe ProcessHtmlResponse(string htmldoc) { BusinessObjects.Recipe re = new BusinessObjects.Recipe(); string expNRecetaLeft = "<h1 itemprop=\"name\" class=\"recipes fn\">"; string expNReceta = expNRecetaLeft + "(?<Title>(\\w+\\s*)+)<"; Regex ex = new Regex(expNReceta, RegexOptions.Multiline | RegexOptions.IgnoreCase); if (ex.IsMatch(htmldoc)) { string match = ex.Match(htmldoc).Groups["Title"].Value; re.Title = match; } HandleDetails(htmldoc, ref re); HandleIngredients(htmldoc, ref re); HandleProcedim(htmldoc, ref re); return re; }
protected List<BusinessObjects.Recipe> ProcessRssResponse(string htmldoc) { var list = new List<BusinessObjects.Recipe>(); XElement channel = XElement.Parse(htmldoc).Elements().First(); var recetas = (from itm in channel.Elements() where itm.Name.LocalName.Equals("item") select itm).ToList(); foreach (XElement xElement in recetas) { string title = xElement.Elements().SingleOrDefault(x => x.Name.LocalName.Equals("title")).Value; string author = xElement.Elements().SingleOrDefault(x => x.Name.LocalName.Equals("author")).Value; string image = xElement.Elements().SingleOrDefault(x => x.Name.LocalName.Equals("image")).Value; string link = xElement.Elements().SingleOrDefault(x => x.Name.LocalName.Equals("link")).Value; var item = new BusinessObjects.Recipe { Author = author, Title = title, ImageUrl = image, LinkUrl = link }; DateTime now = DateTime.Now; Debug.WriteLine("----> Translate Started at {0}", now); TranslateRecipeMicrosoft(item); TimeSpan span = DateTime.Now.Subtract(now); Debug.WriteLine("----> Translate Time Elapsed {0}", span.ToString()); list.Add(item); } return list; }