private AnimeSummary SetAnimeSummaryList(string htmlContent) { var relatedDocument = new HtmlDocument(); relatedDocument.LoadHtml(htmlContent); var alternativeNode = relatedDocument.DocumentNode.SelectNodes("//a[@href]").FirstOrDefault(); var animeSummary = new AnimeSummary { Url = alternativeNode.Attributes["href"].Value, Title = alternativeNode.InnerText }; var stringToParse = alternativeNode.Attributes["href"].Value.Replace( "http://myanimelist.net/anime/", ""); //Sometimes the url does not contain the domain name... stringToParse = stringToParse.Replace("/anime/", ""); var mangaIdString = stringToParse.Substring(0, stringToParse.IndexOf("/", StringComparison.Ordinal)); int mangaAlternativeId; if (Int32.TryParse(mangaIdString, out mangaAlternativeId)) { animeSummary.AnimeId = mangaAlternativeId; } else { animeSummary.AnimeId = 0; } return animeSummary; }
private void SetAnimeSummaryList(List<AnimeSummary> animeSummaries, string htmlContent) { var relatedDocument = new HtmlDocument(); relatedDocument.LoadHtml(htmlContent); foreach (var alternativeNode in relatedDocument.DocumentNode.SelectNodes("//a[@href]").Select(x => x)) { var animeSummary = new AnimeSummary { Url = alternativeNode.Attributes["href"].Value, Title = alternativeNode.InnerText }; var stringToParse = alternativeNode.Attributes["href"].Value.Replace( "/anime/", ""); var mangaIdString = stringToParse.Substring(0, stringToParse.IndexOf("/", StringComparison.Ordinal)); int mangaAlternativeId; if (Int32.TryParse(mangaIdString, out mangaAlternativeId)) { animeSummary.AnimeId = mangaAlternativeId; } else { animeSummary.AnimeId = 0; } animeSummaries.Add(animeSummary); } }