Ejemplo n.º 1
0
        /// <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 Post?GetPost(HtmlNode li, IQuest quest)
        {
            if (li == null)
            {
                throw new ArgumentNullException(nameof(li));
            }

            string author = "";
            string id     = "";
            string text   = "";
            int    number = 0;

            // ID
            id = li.Id.Substring("post_".Length);

            // Number
            var postCount = li.OwnerDocument.GetElementbyId($"postcount{id}");

            if (postCount != null)
            {
                number = int.Parse(postCount.GetAttributeValue("name", "0"));
            }


            HtmlNode postDetails = li.Elements("div").FirstOrDefault(n => n.GetAttributeValue("class", "") == "postdetails");

            if (postDetails != null)
            {
                // Author
                HtmlNode?userinfo = postDetails.GetChildWithClass("div", "userinfo");
                HtmlNode?username = userinfo?.GetChildWithClass("a", "username");
                author = ForumPostTextConverter.CleanupWebString(username?.InnerText);

                // Text
                string postMessageId = "post_message_" + id;

                var message = li.OwnerDocument.GetElementbyId(postMessageId)?.Element("blockquote");

                // Predicate filtering out elements that we don't want to include
                var exclusion = ForumPostTextConverter.GetClassExclusionPredicate("bbcode_quote");

                // Get the full post text.
                text = ForumPostTextConverter.ExtractPostText(message, exclusion, Host);
            }

            Post?post;

            try
            {
                Origin origin = new Origin(author, id, number, Site, GetPermalinkForId(id));
                post = new Post(origin, text);
            }
            catch
            {
                post = null;
            }

            return(post);
        }
Ejemplo n.º 2
0
        private string GetPostText(HtmlDocument page, string id, IQuest quest)
        {
            string postMessageId = $"post_message_{id}";

            var postContents = page.GetElementbyId(postMessageId);

            // Predicate filtering out elements that we don't want to include
            var exclusion = ForumPostTextConverter.GetClassExclusionPredicate("bbcode_quote");

            Uri host = new Uri(quest.ThreadUri.GetLeftPart(UriPartial.Authority) + "/");;

            // Get the full post text.
            return(ForumPostTextConverter.ExtractPostText(postContents, exclusion, host));
        }
Ejemplo n.º 3
0
        private string GetPostText(HtmlNode li, IQuest quest)
        {
            HtmlNode?contentArea = li.GetDescendantWithClass("div", "b-post__content");

            var postTextNode = contentArea?.Descendants("div").FirstOrDefault(a => a.GetAttributeValue("itemprop", "") == "text");

            if (postTextNode != null)
            {
                // Predicate filtering out elements that we don't want to include
                var exclusion = ForumPostTextConverter.GetClassExclusionPredicate("bbcode_quote");

                Uri host = new Uri(quest.ThreadUri.GetLeftPart(UriPartial.Authority) + "/");;

                // Get the full post text.
                return(ForumPostTextConverter.ExtractPostText(postTextNode, exclusion, host));
            }

            return("");
        }
Ejemplo n.º 4
0
        private string GetPostText(HtmlNode li, string id, IQuest quest)
        {
            HtmlNode postDetails = li.Elements("div").FirstOrDefault(n => n.GetAttributeValue("class", "") == "postdetails");

            if (postDetails != null)
            {
                // Text
                string postMessageId = "post_message_" + id;

                var message = li.OwnerDocument.GetElementbyId(postMessageId)?.Element("blockquote");

                // Predicate filtering out elements that we don't want to include
                var exclusion = ForumPostTextConverter.GetClassExclusionPredicate("bbcode_quote");

                Uri host = new Uri(quest.ThreadUri.GetLeftPart(UriPartial.Authority) + "/");;

                // Get the full post text.
                return(ForumPostTextConverter.ExtractPostText(message, exclusion, host));
            }

            return("");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get a completed post from the provided HTML list item.
        /// </summary>
        /// <param name="li">List item that contains the post.</param>
        /// <returns>Returns a post object with required information.</returns>
        private Post?GetPost(HtmlNode li, IQuest quest)
        {
            if (li == null)
            {
                throw new ArgumentNullException(nameof(li));
            }

            string author = "";
            string id     = "";
            string text   = "";
            int    number = 0;

            // ID
            id = li.GetAttributeValue("data-node-id", "");

            if (string.IsNullOrEmpty(id))
            {
                return(null);
            }

            // Author
            var postAuthorNode = li.Descendants("div").FirstOrDefault(a => a.GetAttributeValue("itemprop", "") == "author");
            var authorNode     = postAuthorNode?.GetDescendantWithClass("div", "author");

            if (authorNode != null)
            {
                author = ForumPostTextConverter.CleanupWebString(authorNode.InnerText);
            }

            HtmlNode?contentArea = li.GetDescendantWithClass("div", "b-post__content");

            // Number
            HtmlNode?postCountAnchor = contentArea?.GetDescendantWithClass("a", "b-post__count");

            if (postCountAnchor != null)
            {
                string postNumText = postCountAnchor.InnerText;
                if (postNumText.StartsWith("#", StringComparison.Ordinal))
                {
                    postNumText = postNumText.Substring(1);
                }

                number = int.Parse(postNumText);
            }

            // Text
            var postTextNode = contentArea?.Descendants("div").FirstOrDefault(a => a.GetAttributeValue("itemprop", "") == "text");

            // Predicate filtering out elements that we don't want to include
            var exclusion = ForumPostTextConverter.GetClassExclusionPredicate("bbcode_quote");

            // Get the full post text.
            text = ForumPostTextConverter.ExtractPostText(postTextNode, exclusion, Host);


            Post?post;

            try
            {
                Origin origin = new Origin(author, id, number, Site, GetPermalinkForId(id));
                post = new Post(origin, text);
            }
            catch
            {
                post = null;
            }

            return(post);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get a completed post from the provided HTML div node.
        /// </summary>
        /// <param name="postDiv">Div node that contains the post.</param>
        /// <returns>Returns a post object with required information.</returns>
        private Post?GetPost(HtmlNode postDiv, IQuest quest)
        {
            string author = "";
            string id;
            string text;
            int    number = 0;

            var postTable = postDiv.Descendants("table").FirstOrDefault(a => a.Id.StartsWith("post", StringComparison.Ordinal));

            if (postTable == null)
            {
                return(null);
            }

            id = postTable.Id.Substring("post".Length);

            string postAuthorDivID = "postmenu_" + id;

            var authorAnchor = postTable.OwnerDocument.GetElementbyId(postAuthorDivID).Element("a");

            if (authorAnchor != null)
            {
                author = authorAnchor.InnerText;

                // ??
                if (authorAnchor.Element("span") != null)
                {
                    author = authorAnchor.Element("span").InnerText;
                }
            }

            string postNumberAnchorID = "postcount" + id;

            var anchor = postTable.OwnerDocument.GetElementbyId(postNumberAnchorID);

            if (anchor != null)
            {
                string postNumText = anchor.GetAttributeValue("name", "");
                number = int.Parse(postNumText);
            }

            string postMessageId = "post_message_" + id;

            var postContents = postTable.OwnerDocument.GetElementbyId(postMessageId);

            // Predicate filtering out elements that we don't want to include
            var exclusion = ForumPostTextConverter.GetClassExclusionPredicate("bbcode_quote");

            // Get the full post text.
            text = ForumPostTextConverter.ExtractPostText(postContents, exclusion, Host);


            Post?post = null;

            try
            {
                Origin origin = new Origin(author, id, number, Site, GetPermalinkForId(id));
                post = new Post(origin, text);
            }
            catch
            {
                //post = null;
            }

            return(post);
        }