/// <summary> /// Get a completed post from the provided HTML list item node. /// </summary> /// <param name="li">List item node that contains the post.</param> /// <returns>Returns a post object with required information.</returns> private PostComponents GetPost(HtmlNode li) { if (li == null) { throw new ArgumentNullException(nameof(li)); } string author; string id; string text; int number; // Author and ID are in the basic list item attributes author = PostText.CleanupWebString(li.GetAttributeValue("data-author", "")); id = li.Id.Substring("post-".Length); if (AdvancedOptions.Instance.DebugMode) { author = $"{author}_{id}"; } // Get the primary content of the list item HtmlNode primaryContent = li.GetChildWithClass("primaryContent"); // On one branch, we can get the post text HtmlNode messageContent = primaryContent.GetChildWithClass("messageContent"); HtmlNode postBlock = messageContent.Element("article").Element("blockquote"); // Predicate filtering out elements that we don't want to include List <string> excludedClasses = new List <string> { "bbCodeQuote", "messageTextEndMarker", "advbbcodebar_encadre", "advbbcodebar_article", "adv_tabs_wrapper", "adv_slider_wrapper" }; if (AdvancedOptions.Instance.IgnoreSpoilers) { excludedClasses.Add("bbCodeSpoilerContainer"); } var exclusions = PostText.GetClassesExclusionPredicate(excludedClasses); // Get the full post text. text = PostText.ExtractPostText(postBlock, exclusions, Host); // On another branch of the primary content, we can get the post number. HtmlNode messageMeta = primaryContent.GetChildWithClass("messageMeta"); // HTML parsing of the post was corrupted somehow. if (messageMeta == null) { return(null); } HtmlNode publicControls = messageMeta.GetChildWithClass("publicControls"); HtmlNode postNumber = publicControls.GetChildWithClass("postNumber"); string postNumberText = postNumber.InnerText; // Skip the leading # character. if (postNumberText.StartsWith("#", StringComparison.Ordinal)) { postNumberText = postNumberText.Substring(1); } number = int.Parse(postNumberText); PostComponents post; try { post = new PostComponents(author, id, text, number); } catch (Exception e) { ErrorLog.Log(e); post = null; } return(post); }