// Get feed text from parentNode. string GetFeedText(HtmlNode parentNode) { string feedContent, feedContentFull; if (IsNodeWithClass(parentNode, "WB_detail")) { feedContent = "feed_list_content"; feedContentFull = "feed_list_content_full"; } else if (IsNodeWithClass(parentNode, "WB_expand")) { feedContent = "feed_list_reason"; feedContentFull = "feed_list_reason_full"; } else { return(""); } var WB_text = SelectChildNodeByNodeType(parentNode, feedContentFull); if (WB_text == null) { WB_text = SelectChildNodeByNodeType(parentNode, feedContent); } if (WB_text == null) { return(""); } var rawText = new FeedText(WB_text.InnerHtml); return(rawText.ToMarkdown()); }
// Get selected comments. List <Comment> CheckCommentList(HtmlNode list_ul, bool enableSubcommentList) { List <Comment> comments = new List <Comment>(); foreach (var list_li in list_ul.ChildNodes) { if (list_li.NodeType == HtmlNodeType.Element && IsNodeWithClass(list_li, "list_li")) { var list_con = SelectChildNodeByClass(list_li, "list_con"); var WB_text = SelectChildNodeByClass(list_con, "WB_text"); string commentName = WB_text.Element("a").InnerText; if (Accounts.OriginalPlan.ContainsKey(commentName)) { // Get comment text. string rawCommentText = WB_text.InnerHtml; int commentStartPos = rawCommentText.IndexOf(":") + 1; rawCommentText = rawCommentText.Substring(commentStartPos); var markdownCommentText = new FeedText(rawCommentText).ToMarkdown(); // Get comment image if any. var WB_media_wrap = SelectChildNodeByClass(list_con, "WB_media_wrap"); if (WB_media_wrap != null) { var imageLink = SelectChildNodeByClass(WB_media_wrap, "media_box", "WB_media_a", "WB_pic") .Element("img").GetAttributeValue("src", "/"); // Change the size. int sizeTagPos = imageLink.IndexOf(".sinaimg.cn/") + ".sinaimg.cn/".Length; int sizeTagEndPos = imageLink.IndexOf('/', sizeTagPos); string sizeTag = imageLink.Substring(sizeTagPos, sizeTagEndPos - sizeTagPos); imageLink = imageLink.Replace(sizeTag, "mw690"); // Replace with the new link. markdownCommentText = markdownCommentText.Replace("javascript:void(0);", imageLink); } // Get comment time. var WB_from = SelectChildNodeByClass(list_con, "WB_func", "WB_from"); string rawCommentTime = WB_from.InnerText; // TODO: DateTime.TryParse() // Get subcomments. List <Comment> subcomments = new List <Comment>(); if (enableSubcommentList) { var sub_list_ul = SelectChildNodeByClass(list_con, "list_box_in", "list_ul"); subcomments = CheckCommentList(sub_list_ul, false); } comments.Add(new Comment(Accounts.OriginalPlan[commentName], rawCommentTime, markdownCommentText, subcomments)); } } } return(comments.Count == 0 ? null : comments); }