private Book SetBookData(Book book, string field, string value) { switch (field) { case "Edição": book.Edition = SafeConvert.ToInt(value); break; case "Editora": book.Publisher = value; break; case "ISBN": book.ISBN = value; break; case "Ano": book.Year = SafeConvert.ToInt(value); break; case "Páginas": book.Pages = SafeConvert.ToInt(value); break; case "Tradutor": book.Translators = value; break; } return book; }
private List<Book> GetBooksFromEdition(string title, string author, string editionsUrl) { List<Book> books = new List<Book>(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(GetContent(editionsUrl)); HtmlNodeCollection editions = doc.DocumentNode.SelectNodes("//div[preceding-sibling::div[@id='menubusca']]//div[position()=3]//div[@style='float:left; font-size:11px; font-family:arial; margin:10px 8px 0px 0px; width:250px; border:red 0px solid; line-height:18px;']"); Book book = null; if (editions != null) { foreach (HtmlNode edition in editions) { HtmlNode img = edition.SelectSingleNode(".//img"); string bookCover = string.Empty; if (img != null && img.Attributes["src"].Value != "/img/geral/semcapa_m.gif") bookCover = img.Attributes["src"].Value; string rx = @"(\w+):<\/span>\s([\w\s,]+)<br>"; MatchCollection matches = Regex.Matches(edition.InnerHtml, rx, RegexOptions.IgnoreCase); book = new Book(); book.Title = title; book.Author = author; book.Cover = bookCover; foreach (Match m in matches) { if (m.Success && m.Groups.Count == 3) SetBookData(book, m.Groups[1].Value, m.Groups[2].Value); } books.Add(book); } } return books; }