public Task <ObservableCollection <ComicListStructure> > ExtractLatestComics(string source) { ComicListStructure comicListStructure = new ComicListStructure(); var doc = new HtmlDocument(); doc.LoadHtml(source); var ComicListNode = doc.GetElementbyId("Comics"); for (int i = 0; i < ComicListNode.ChildNodes.Count; i++) { // Since the Elements are in ODD Index, we need to incriment by 1 first here for Usage. i++; int count = ComicListNode.ChildNodes.Count; try { _comicList.Add(new ComicListStructure { comicTitle = CommonFunctions.ToUpperCase(Convert.ToString(ComicListNode.ChildNodes[i].ChildNodes[3].FirstChild.ChildNodes[0].InnerText)), comicLink = ServiceUrl.base_comic_url + Convert.ToString(ComicListNode.ChildNodes[i].ChildNodes[1].FirstChild.Attributes[0].Value), comicIssue = Convert.ToString(ComicListNode.ChildNodes[i].ChildNodes[5].FirstChild.ChildNodes[0].InnerText).Replace("Issue", "").Replace("#", "").Trim(), comicCoverImage = ServiceUrl.base_comic_url + Convert.ToString(ComicListNode.ChildNodes[i].ChildNodes[1].ChildNodes[0].ChildNodes[0].Attributes[1].Value) }); } catch (Exception) { //Console.WriteLine("I right Now : " + i); continue; } } return(Task.FromResult(_comicList)); }
public async Task <ObservableCollection <ComicListStructure> > ExtractComicSearch(string searchText, string source) { ComicListStructure comicListStructure = new ComicListStructure(); var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(source); var comicLinkNodes = doc.DocumentNode.SelectNodes("//h3[contains(@class,'title')]"); var comicLastSearchNode = doc.DocumentNode.SelectSingleNode("//a[contains(@title,'Go to last page')]"); int lastSearchPageNumber = Convert.ToInt16(comicLastSearchNode.Attributes["href"].Value.Split('=')[1].Trim()); await ExtractLinksFromNodes(comicLinkNodes); // Currently disabling further results. // This needs new implementation. //for (int i = 1; i <= lastSearchPageNumber + 1; i++) //{ // /* If last Search Page = 1, then we do not have multiple // * search pages. // * So, we do not need to iterate over things. We're pretty much // * done here. // */ // if (i != lastSearchPageNumber) // { // string webResponse = await LatestComicFetcher.GetComicPageContent(ServiceUrl.base_comic_search_url + searchText + "?page=" + i); // doc.LoadHtml(webResponse); // comicLinkNodes = doc.DocumentNode.SelectNodes("//h3[contains(@class,'title')]"); // await ExtractLinksFromNodes(comicLinkNodes); // } //} _comicList.Clear(); // Clear any previous data. ComicDetailStructure comicDetailStructure_new = new ComicDetailStructure(); foreach (var searchUrl in urlList) { try { comicDetailStructure_new = await GetComicDetails(searchUrl); _comicList.Add(new ComicListStructure { comicTitle = comicDetailStructure_new.comicTitle, comicLink = searchUrl, comicIssue = comicDetailStructure_new.comicDescription, comicCoverImage = ServiceUrl.base_comic_url + comicDetailStructure_new.comicImage } ); } catch (Exception ComicExtractionException) { Crashes.TrackError(ComicExtractionException); continue; } } return(_comicList); }
public Task <ObservableCollection <ComicListStructure> > ExtractLatestComics(string source) { ComicListStructure comicListStructure = new ComicListStructure(); var doc = new HtmlDocument(); doc.LoadHtml(source); var comicInfo = doc.DocumentNode.SelectNodes("//div[contains(@class,'popbox')]"); foreach (var item in comicInfo) { // Popular titles show also the Manga. So, we need to remove those. if (item.ChildNodes[3].ChildNodes[0].Attributes[0].Value.Contains("/manga/")) { continue; } try { _comicList.Add(new ComicListStructure { comicTitle = Convert.ToString(item.ChildNodes[1].InnerText), comicLink = ServiceUrl.base_comic_url + Convert.ToString(item.ChildNodes[3].ChildNodes[0].Attributes[0].Value), comicIssue = Convert.ToString(item.ChildNodes[5].InnerText).Replace("Issue", "").Replace("#", "").Trim(), comicCoverImage = ServiceUrl.base_comic_url + Convert.ToString(item.ChildNodes[3].FirstChild.FirstChild.EndNode.Attributes[1].Value) }); } catch (Exception) { _comicList.Add(new ComicListStructure { comicTitle = Convert.ToString(item.ChildNodes[1].InnerText), comicLink = ServiceUrl.base_comic_url + Convert.ToString(item.ChildNodes[3].ChildNodes[0].Attributes[0].Value), comicIssue = Convert.ToString(item.ChildNodes[5].InnerText).Replace("Issue", "").Replace("#", "").Trim(), comicCoverImage = ServiceUrl.base_comic_url + Convert.ToString(item.ChildNodes[3].FirstChild.ChildNodes[1].Attributes[1].Value) } ); } } return(Task.FromResult(_comicList)); }