/// <summary> /// Breaks apart the result of the serach and reurns a list of FanFic that were found in the result /// </summary> /// <returns></returns> public override List <FanFic> DecodeHTML() { var nodes = Result.DocumentNode.SelectNodes("//li[contains(@class, 'work')]"); List <FanFic> fics = new List <FanFic>(); if (nodes != null) { foreach (HtmlNode node in nodes) { // TODO: Determine error problems when reading information try { FanFic fic = new FanFic(); // Gather story information var header_nodes = node.SelectNodes(".//h4[contains(@class, 'heading')]//a"); fic.Title = new Tuple <string, string>(header_nodes[0].InnerText, link_base + header_nodes[0].Attributes["href"].Value); fic.Author = new Tuple <string, string>(header_nodes[1].InnerText, link_base + header_nodes[1].Attributes["href"].Value); try // non-essential { // Get fandom information var fandom_node = node.SelectSingleNode(".//h5[contains(@class, 'fandoms')]"); foreach (var fandom in fandom_node.SelectNodes(".//a")) { fic.Fandoms.Add(new Tuple <string, string>(fandom.InnerText, link_base + fandom.Attributes["href"].Value)); } } catch { } try // non-essential { // Get tag information var tag_nodes = node.SelectNodes(".//ul[contains(@class, 'tags')]//li"); foreach (var tag_node in tag_nodes) { var tag = tag_node.SelectSingleNode(".//a"); fic.AddTag(new Tuple <string, string>(tag.InnerText, link_base + tag.Attributes["href"].Value)); } } catch { } try // non-essential { // Get fic description var fic_desc = node.SelectSingleNode(".//blockquote[contains(@class, 'summary')]"); fic.Description = fic_desc.InnerText; } catch { } try { var fic_likes = node.SelectSingleNode(".//dd[contains(@class, 'kudos')]"); fic.Likes = Convert.ToInt64(fic_likes.InnerText); } catch { } fics.Add(fic); } catch { continue; //TODO: Fix the error catching later } } } return(fics); }
public override List <FanFic> DecodeHTML() { List <FanFic> fics = new List <FanFic>(); var nodes = Result.DocumentNode.SelectNodes("//div[contains(@class, 'z-list')]"); if (nodes != null) { foreach (var node in nodes) { FanFic fic = new FanFic(); try { // Get title info var title_node = node.SelectSingleNode(".//a[contains(@class, 'stitle')]"); fic.Title = new Tuple <string, string>(title_node.InnerText, link_base + title_node.Attributes["href"].Value); // Get Author info var author_node = node.SelectNodes(".//a")[1]; // Get author info fic.Author = new Tuple <string, string>(author_node.InnerText, author_node.Attributes["href"].Value); // Get fic info var data_node = node.SelectSingleNode(".//div[contains(@class, 'z-padtop2')]"); var fic_data = data_node.InnerText.Split("-", StringSplitOptions.RemoveEmptyEntries).ToList(); fic_data.ForEach(x => x = x.Trim()); // removing trailing and leading whitespace fic.Fandoms.Add(new Tuple <string, string>(fic_data[0], "")); // Find tag information if (fic_data.Last().Contains("Complete") && fic_data.FindIndex(x => x.Contains("Published")) != fic_data.Count - 2) { // Run if the last item is complete and second to last is not Published date -- means there are tags fic.Tags.Add(new Tuple <string, string>(fic_data[fic_data.Count - 2], "")); } else if (!fic_data.Last().Contains("Published") && !fic_data.Last().Contains("Complete")) { // Run if the last item is not published and the fic is not complete fic.Tags.Add(new Tuple <string, string>(fic_data.Last(), "")); } try { // Get favorites information var fav_str = fic_data.Find(x => x.Contains("Favs")); var fav_num = fav_str.Split(" ", StringSplitOptions.RemoveEmptyEntries).Last(); fav_num = fav_num.Replace(",", ""); fic.Likes = Convert.ToInt64(fav_num); } catch { fic.Likes = 0; } // Get description info var desc_data = node.SelectSingleNode(".//div[contains(@class, 'z-padtop')]"); fic.Description = desc_data.InnerText.Replace(data_node.InnerText, ""); fics.Add(fic); } catch { continue; } } } return(fics); }
public override List <FanFic> DecodeHTML() { var nodes = Result.DocumentNode.SelectNodes("//div[contains(@class, 'results-story-item')]"); List <FanFic> fics = new List <FanFic>(); if (nodes != null) { foreach (HtmlNode node in nodes) { // TODO: Determine error problems when reading information try { FanFic fic = new FanFic(); // Gather basic story info var title_node = node.SelectSingleNode(".//h5[contains(@class, 'story-title-heading')]"); var title_link_node = node.SelectSingleNode(".//a[contains(@class, 'on-result')]"); var author_node = node.SelectSingleNode(".//div[contains(@class, 'cover')]//img"); fic.Title = new Tuple <string, string>(title_node.InnerText, link_base + title_link_node.Attributes["href"].Value); fic.Author = new Tuple <string, string>(author_node.Attributes["alt"].Value.Split(" by ").Last().Trim(), ""); // Gather description var desc_node = node.SelectSingleNode(".//div[contains(@class, 'content')]//p"); fic.Description = desc_node.InnerText; // Is this story paid? var paid_node = node.SelectSingleNode(".//div[contains(@class, 'paid-indicator')]"); if (paid_node != null) { fic.PaidStory = true; } // Get likes and views var meta_node = node.SelectSingleNode(".//div[contains(@class, 'meta')]"); try { var reads_node = meta_node.SelectSingleNode(".//small[contains(@class, 'reads')]"); if (ConvertStringMetaNumbers(reads_node.InnerText, out long views)) { fic.Views = views; } } catch { } try { var likes_node = meta_node.SelectSingleNode(".//small[contains(@class, 'votes')]"); if (ConvertStringMetaNumbers(likes_node.InnerText, out long likes)) { fic.Likes = likes; } } catch { } // Get completion status var completed_node = node.SelectSingleNode(".//div[contains(@class, 'story-status')]//span"); if (completed_node != null) { fic.Completed = true; } else { fic.Completed = false; } // Get Tags var tag_nodes = node.SelectNodes(".//button[contains(@class, 'tag-item')]"); foreach (var tag in tag_nodes) { fic.Tags.Add(new Tuple <string, string>(tag.InnerText, "")); } //Add fic to final list fics.Add(fic); } catch { continue; } } } return(fics); }