public async Task <Post> getPost() { Post resultPost = new Post(); if (rootNode == null) { return(new Post()); } var article = rootNode.SelectSingleNode("//article"); var articleHeader = rootNode.SelectSingleNode("//header"); var articleFooter = rootNode.SelectSingleNode("//footer"); resultPost.id = postId; resultPost.title = article.SelectSingleNode(".//h1[@class='topic-title word-wrap']").InnerText; resultPost.author = article.SelectSingleNode(".//a[@rel='author']").InnerText; await resultPost.author_image.SetBitmapAsync( await webManager.getCachedImageAsync( normalizeImageUriDebug( article.SelectSingleNode(".//img[@class='avatar']") .Attributes["src"].Value))); var blogNode = article.SelectSingleNode(".//a[@class='topic-blog'] | .//a[@class='topic-blog private-blog']"); resultPost.blog = blogNode.InnerText; resultPost.blog_id = UriParser.getLastPart(blogNode .Attributes["href"].Value); resultPost.rating = article.SelectSingleNode(".//div[@class='vote-item vote-count']").InnerText; resultPost.votesTotal = article.SelectSingleNode(".//div[@class='vote-item vote-count']") .Attributes["title"].Value; resultPost.text = await htmlParser.convertNodeToParagraph( article.SelectSingleNode(".//div[@class='topic-content text']")); resultPost.datatime = article.SelectSingleNode(".//time").InnerText.Replace("\n", String.Empty).Replace("\t", String.Empty); foreach (HtmlNode node in article.SelectNodes(".//a[@rel='tag']")) { resultPost.tags += HtmlEntity.DeEntitize(node.InnerText) + " "; } resultPost.commentsCount = rootNode.SelectSingleNode(".//span[@id='count-comments']").InnerText; var new_comments_counter = rootNode.SelectSingleNode(".//div[@id='new_comments_counter']"); if (new_comments_counter != null) { int.TryParse(new_comments_counter.Attributes["data-id-comment-last"].Value, out lastComment); resultPost.lastComment = lastComment; } return(resultPost); }
public async Task <List <Post> > getPosts() { List <Post> resultPosts = new List <Post>(); if (rootNode == null) { return(null); } var articles = rootNode.SelectNodes("//article"); foreach (HtmlNode article in articles) { var articleHeader = article.SelectSingleNode(".//header"); var articleTitle = articleHeader.SelectSingleNode(".//h1/a").InnerText; var articleUri = new Uri(articleHeader.SelectSingleNode(".//h1/a") .Attributes["href"].Value); var articleId = Int32.Parse(articleUri .Segments.Last() .Replace(".html", String.Empty)); var articleRating = articleHeader.SelectSingleNode(".//span/i").InnerText; var articleAuthor = articleHeader.SelectSingleNode(".//a[@rel]").InnerText; var articleAuthorImageUri = articleHeader.SelectSingleNode(".//img") .Attributes["src"].Value; var articleBlog = articleHeader.SelectSingleNode(".//a[@class]").InnerText; var articleBlogId = articleHeader.SelectSingleNode(".//*[@class='topic-blog']") .Attributes["href"].Value; articleBlogId = UriParser.getLastPart(articleBlogId); var articleBody = await htmlParser.convertNodeToParagraph( article.SelectSingleNode(".//div[@class='topic-content text']")); var articleFooter = article.SelectSingleNode(".//footer[@class='topic-footer']"); var articleTags_tmp = articleFooter.SelectNodes(".//a[@rel]"); string articleTags = ""; foreach (HtmlNode node in articleTags_tmp) { articleTags += node.InnerText + " "; } var articleDatatime = articleFooter.SelectSingleNode(".//time").InnerText; var articleCommentsCount = articleFooter.SelectSingleNode(".//li[@class='topic-info-comments']").InnerText.Trim(); SoftwareBitmapSource source = new SoftwareBitmapSource(); await source.SetBitmapAsync( await webManager.getCachedImageAsync(normalizeImageUriDebug(articleAuthorImageUri))); resultPosts.Add(new Post { id = articleId, title = articleTitle, author = articleAuthor, author_image = source, blog = " " + articleBlog, // Чтобы не сливался с "в блоге" blog_id = articleBlogId, rating = articleRating, text = articleBody, //text = HtmlEntity.DeEntitize(articleBody).Trim(), tags = articleTags, datatime = articleDatatime, commentsCount = articleCommentsCount, }); } return(resultPosts); }