public static void ToParserBookModel( this ParserBookModel bookModel, string Title, string Annotation, string Cover, string NumberOfPages, string Format, string CostPaper, string CostDigital, string Year, string BuyUri, string ImageUri, List <string> AuthorsNames, string TechnologiesName, string PublishingName ) { }
public ParserBookModel GetEksmoBook(string uri) { try { ParserBookModel result = new ParserBookModel(); var root = _parser.GetRootNode(uri); var imageUri = root .Descendants().First(a => a.GetAttributeValue("class", "").Contains("cont-book-pic")) .Descendants("a").First().GetAttributeValue("href", ""); var annotation = _parser.GetNormalizedString( root.Descendants() .First(a => a.GetAttributeValue("class", "").Contains("spoiler__text t annotation")).InnerHtml); var cost = root.Descendants() .First(a => a.GetAttributeValue("class", "").Contains("price__number")).InnerHtml + root.Descendants() .First(a => a.GetAttributeValue("class", "").Contains("price__currency")).InnerHtml; var title = root.Descendants() .First(a => a.GetAttributeValue("class", "").Contains("h h_2 h_no-offset book-detail-h1")) .InnerHtml; var authorName = root.Descendants() .First(a => a.GetAttributeValue("class", "").Contains("author")) .Descendants("a").First().InnerText; var authorLink = root.Descendants() .First(a => a.GetAttributeValue("class", "").Contains("author")) .Descendants("a").First().Attributes["href"].Value; var technology = root.Descendants() .First(a => a.GetAttributeValue("class", "").Contains("a a_orange series_link")).InnerText; string yearInfo = ""; try { yearInfo = root.Descendants() .First(a => a.GetAttributeValue("class", "").Contains("content-text-title")) .ParentNode.Descendants().Last().InnerText; if (yearInfo.ToUpper() == "ПРЕДЗАКАЗ") { yearInfo = "2019"; } else { DateTime year = Convert.ToDateTime(yearInfo); yearInfo = year.Year.ToString(); } } catch (Exception e) { Console.WriteLine(e); yearInfo = "2019"; } } catch (Exception e) { Console.WriteLine(e); } return(null); }
public ParserBookModel GetPiterBook(string uri) { ParserBookModel result = new ParserBookModel(); var root = GetRootNode(uri); var imageUri = root.Descendants() .Where(b => b.GetAttributeValue("class", "").Contains("coverProduct")).ToList().First() .ParentNode.ChildNodes .Where(n => n.Name.Contains("img")).ToList().First() .GetAttributeValue("src", ""); var annotation = root.Descendants() .Where(a => a.GetAttributeValue("class", "").Contains("tabs")).ToList().First().Descendants() .Where(b => b.GetAttributeValue("id", "").Contains("tab-1")).ToList().First().InnerText; var costs = root.Descendants() .Where(a => a.GetAttributeValue("class", "").Contains("price")) .Where(b => b.Name.Contains("div")) .Where(c => c.InnerText.StartsWith("1") || c.InnerText.StartsWith("2") || c.InnerText.StartsWith("3") || c.InnerText.StartsWith("4") || c.InnerText.StartsWith("5") || c.InnerText.StartsWith("6") || c.InnerText.StartsWith("7") || c.InnerText.StartsWith("8") || c.InnerText.StartsWith("9")).ToList(); var costPaper = costs.First().InnerText; var costDigital = costs.Last().InnerText; var bookInfoNode = GetBookInfoNode(root); var title = GetTitleBook(bookInfoNode); var authors = GetAuthors(bookInfoNode); var description = bookInfoNode.Descendants() .Where(a => a.GetAttributeValue("class", "").Contains("clearfix")).ToList(); string technology = ""; string year = ""; string numberOfPages = ""; string format = ""; foreach (var item in description) { if (item.OuterHtml.ToLower().Contains("тема")) { technology = GetNormalizedString(item.ChildNodes[3].InnerText); } else if (item.OuterHtml.ToLower().Contains("год")) { year = GetNormalizedString(item.ChildNodes[3].InnerText); } else if (item.OuterHtml.ToLower().Contains("страниц")) { numberOfPages = GetNormalizedString(item.ChildNodes[3].InnerText); } else if (item.OuterHtml.ToLower().Contains("формат")) { format = GetNormalizedString(item.ChildNodes[3].InnerText); } } result.Annotation = annotation; result.Cover = "Не указано"; result.Format = format; result.Title = title; result.Year = year; result.AuthorsNames = authors; result.NumberOfPages = numberOfPages; result.CostDigital = costDigital; result.CostPaper = costPaper; result.BuyUri = uri; result.ImageUri = imageUri; result.TechnologiesName = technology; result.PublishingName = "ПИТЕР"; return(result); }