private async Task <PrivateMessage> ParseMessage(string result) { var document = await new HtmlParser().ParseAsync(result); var privateMessage = new PrivateMessage(); var postCheck = document.QuerySelector("div[id='post']"); if (postCheck != null) { var titleCheck = postCheck.QuerySelector("div div strong"); if (titleCheck != null) { privateMessage.Title = WebUtility.HtmlDecode(titleCheck.TextContent.FixaRadbrytningar()); } var messageCheck = postCheck.QuerySelector("div[class='post_message']"); if (messageCheck != null) { var messageData = messageCheck.InnerHtml; if (_options.RenderEmoticons) { messageData = _options.ReplaceSmileys(messageData); } messageData = messageData.FixLeaveLink(); privateMessage.Message = _options.GetHtmlHeaders() + messageData + _options.GetHtmlFooter(); } var tokenCheck = document.QuerySelector("input[name='csrftoken']"); if (tokenCheck != null) { privateMessage.Token = tokenCheck.Attributes["value"].Value; } var folderIdCheck = document.QuerySelector("input[name='folderid']"); if (folderIdCheck != null) { privateMessage.FolderId = folderIdCheck.Attributes["value"].Value; } } return(privateMessage); }
private async Task <ForumThread> ParseSinglePost(string result) { var parser = new HtmlParser(); var singlePost = await parser.ParseAsync(result); var pageNameCheck = singlePost.QuerySelector("title"); bool userLoggedIn = singlePost.QuerySelector("a.btn-quote-multiple") != null; // hack - denna knapp verkar bara renderas när man är inloggad string pageName = WebUtility.HtmlDecode(pageNameCheck.TextContent).Replace("Flashback Forum - ", ""); var parentCheck = singlePost.QuerySelector("div.well strong a"); string parentId = ""; if (parentCheck != null) { parentId = parentCheck.Attributes["href"].Value.Replace("/", ""); } var replyIdCheck = singlePost.QuerySelector("div#post div.post"); string replyId = ""; if (replyIdCheck != null) { replyId = replyIdCheck.Attributes["id"].Value; replyId = replyId.Replace("post", ""); } var post = singlePost.QuerySelectorAll("div#post"); string html = _options.GetHtmlHeaders() + BuildHtmlForForumThreads(post, userLoggedIn) + _options.GetHtmlFooter(); return(new ForumThread() { Title = pageName, CurrentPage = 1, ShowNavigation = false, MaxPages = 1, ParentId = parentId, Html = html, Id = parentId, ReplyId = replyId }); }