当前位置: 首页>>代码示例>>C#>>正文


C# HtmlDocument.WhereOfDescendantsWithClass方法代码示例

本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.WhereOfDescendantsWithClass方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.WhereOfDescendantsWithClass方法的具体用法?C# HtmlDocument.WhereOfDescendantsWithClass怎么用?C# HtmlDocument.WhereOfDescendantsWithClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlAgilityPack.HtmlDocument的用法示例。


在下文中一共展示了HtmlDocument.WhereOfDescendantsWithClass方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSentMessages

        public async Task<List<MalMessageModel>> GetSentMessages(int page = 1)
        {
            try
            {
                var client = await MalHttpContextProvider.GetHttpContextAsync();
                string path = $"/mymessages.php?go=sent";
                var res = await client.GetAsync(path);
                var body = await res.Content.ReadAsStringAsync();


                var output = new List<MalMessageModel>();

                var doc = new HtmlDocument();
                doc.LoadHtml(body);
                output.AddRange(
                    doc.WhereOfDescendantsWithClass("div", "message read spot2 clearfix")
                        .Select(ParseOutboxHtmlToMalMessage));


                return output;
            }
            catch (WebException)
            {
                MalHttpContextProvider.ErrorMessage("Messages");
            }
            return new List<MalMessageModel>();
        }
开发者ID:Mordonus,项目名称:MALClient,代码行数:27,代码来源:MalMessagesQuery.cs

示例2: GetMessages

        public async Task<List<MalMessageModel>> GetMessages(int page = 1)
        {
            var client = await MalHttpContextProvider.GetHttpContextAsync();
            string path = $"/mymessages.php?go=&show={page*20 - 20}";
            var res = await client.GetAsync(path);
            var body = await res.Content.ReadAsStringAsync();


            var output = new List<MalMessageModel>();
            if (body.Contains("You have 0 messages"))
                return output;

            var doc = new HtmlDocument();
            doc.LoadHtml(body);
            output.AddRange(
                doc.WhereOfDescendantsWithClass("div", "message unread spot1 clearfix")
                    .Select(msgNode => ParseInboxHtmlToMalMessage(msgNode, false)));
            output.AddRange(
                doc.WhereOfDescendantsWithClass("div", "message read spot1 clearfix")
                    .Select(msgNode => ParseInboxHtmlToMalMessage(msgNode, true)));


            return output;
        }
开发者ID:Mordonus,项目名称:MALClient,代码行数:24,代码来源:MalMessagesQuery.cs

示例3: GetVideos

        public async Task<List<AnimeVideoData>> GetVideos()
        {
            var output = new List<AnimeVideoData>();
            var raw = await GetRequestResponse(false);
            if (string.IsNullOrEmpty(raw))
                return output;

            var doc = new HtmlDocument();
            doc.LoadHtml(raw);

            try
            {
                foreach (var videoNode in doc.WhereOfDescendantsWithClass("div", "video-list-outer-vertical"))
                {
                    var current = new AnimeVideoData();

                    var link = videoNode.ChildNodes.First(node => node.Name == "a");
                    current.Thumb = link.Attributes["data-bg"].Value;
                    if(current.Thumb.Contains("banned"))
                        continue;
                    current.AnimeId = int.Parse(link.Attributes["data-anime-id"].Value);

                    var href = link.Attributes["href"].Value;
                    var pos = href.IndexOf('?');
                    href = href.Substring(0, pos);
                    current.YtLink = $"https://www.youtube.com/watch?v={href.Split('/').Last()}";

                    current.Name =
                        WebUtility.HtmlDecode(
                            videoNode.FirstOfDescendantsWithClass("div", "info-container").InnerText.Trim());

                    current.AnimeTitle = WebUtility.HtmlDecode(videoNode.Descendants("a").Last().InnerText.Trim());

                    output.Add(current);
                }
            }
            catch (Exception)
            {
                //
            }

            return output;
        }
开发者ID:Mordonus,项目名称:MALClient,代码行数:43,代码来源:PopularVideosQuery.cs

示例4: GetAnime

        public async Task<List<SeasonalAnimeData>> GetAnime()
        {

            var output =
                await
                    DataCache.RetrieveData<List<SeasonalAnimeData>>(
                        _genreMode ? $"genre_{_genre}_{_page}" : $"studio_{_studio}_{_page}",
                        _genreMode ? "AnimesByGenre" : "AnimesByStudio", 7) ??
                new List<SeasonalAnimeData>();
            if (output.Count > 0)
                return output;

            var raw = await GetRequestResponse();
            if (string.IsNullOrEmpty(raw))
                return output;

            var doc = new HtmlDocument();
            doc.LoadHtml(raw);
            int i = 0;
            try
            {
                foreach (var htmlNode in doc.WhereOfDescendantsWithClass("div", "seasonal-anime js-seasonal-anime"))
                {
                    var model = AnimeSeasonalQuery.ParseFromHtml(htmlNode,i,false);
                    if(model == null)
                        continue;
                    output.Add(model);
                    i++;
                }
            }
            catch (Exception)
            {
                //ejchtiemel
            }

            if(_genreMode)
                DataCache.SaveData(output, $"genre_{_genre}_page{_page}", "AnimesByGenre");
            else
                DataCache.SaveData(output, $"studio_{_studio}_page{_page}", "AnimesByStudio");

            return output;
        }
开发者ID:Mordonus,项目名称:MALClient,代码行数:42,代码来源:AnimeGenreStudioQuery.cs

示例5: GetPeekPosts

        public async Task<ForumIndexContent> GetPeekPosts()
        {
            var output = new ForumIndexContent();
            var raw = await GetRequestResponse();
            if (string.IsNullOrEmpty(raw))
                return null;
            var doc = new HtmlDocument();
            doc.LoadHtml(raw);

            var list = new List<ForumBoardEntryPeekPost>(2);
            int i = 0;
            foreach (var topics in doc.WhereOfDescendantsWithClass("ul", "topics"))
            {
                try
                {
                    foreach (var post in topics.Descendants("li"))
                    {
                        i++;
                        try
                        {
                            if (i == 5 || i == 6) //skip db midifiaction board
                                continue;
                            //if(i == 9) //add one more because suggestions have one post
                            //    list.Add(new ForumBoardEntryPeekPost());

                            var current = new ForumBoardEntryPeekPost();
                            current.PostTime = WebUtility.HtmlDecode(post.FirstOfDescendantsWithClass("span", "date di-ib pt4 fs10 fn-grey4").InnerText.TrimEnd('»'));
                            var titleNode = post.FirstOfDescendantsWithClass("a", "topic-title-link");
                            current.Title = WebUtility.HtmlDecode(titleNode.InnerText);
                            current.Id = titleNode.Attributes["href"].Value.Split('=').Last();
                            var img = post.Descendants("img").First();
                            current.User.ImgUrl = img.Attributes["src"].Value;
                            current.User.Name = img.Attributes["alt"].Value;
                            list.Add(current);
                            if (list.Count == 2) //assume we have 2 for each board
                            {
                                output.ForumBoardEntryPeekPosts.Add(list);
                                list = new List<ForumBoardEntryPeekPost>();
                            }
                        }
                        catch (Exception)
                        {
                            //
                        }                     
                    }
                }
                catch (Exception)
                {
                   //
                }                  
            }

            try
            {
                int block = 0;
                var sideBlocks = doc.WhereOfDescendantsWithClass("div", "forum-side-block").Take(4);
                foreach (var sideBlock in sideBlocks)
                {
                    var postList = new List<ForumPostEntry>();
                    foreach (var post in sideBlock.Descendants("li"))
                    {
                        var current = new ForumPostEntry();

                        var titleNode = post.FirstOfDescendantsWithClass("a", "title");
                        current.Id = titleNode.Attributes["href"].Value.Split('=').Last();
                        current.Title = WebUtility.HtmlDecode(titleNode.InnerText.Trim());

                        current.ImgUrl = post.Descendants("img").First().Attributes["src"].Value;

                        var infoSpan = post.FirstOfDescendantsWithClass("span", "information di-ib fs10 fn-grey4");

                        current.Created = infoSpan.ChildNodes[0].InnerText.Trim();
                        current.Created = current.Created.Substring(0, current.Created.Length - 3); //remove "by"

                        current.Op = infoSpan.Descendants("a").First().InnerText.Trim();

                        postList.Add(current);
                    }
                    switch (block)
                    {
                        case 0:
                            output.PopularNewTopics = postList;
                            break;
                        case 1:
                            output.RecentPosts = postList;
                            break;
                        case 2:
                            output.AnimeSeriesDisc = postList;
                            break;
                        default:
                            output.MangaSeriesDisc = postList;
                            break;
                    }
                    block++;
                }
            }
            catch (Exception)
            {
                //
            }
//.........这里部分代码省略.........
开发者ID:Mordonus,项目名称:MALClient,代码行数:101,代码来源:ForumBoardIndexContentQuery.cs

示例6: GetArticlesIndex

        public async Task<List<MalNewsUnitModel>> GetArticlesIndex(bool force = false)
        {
            if (!force)
            {
                if (_cachedData.ContainsKey(_mode))
                    return _cachedData[_mode];
                var possibleData = await DataCache.RetrieveArticleIndexData(_mode);
                if (possibleData != null && possibleData.Count > 0)
                    return possibleData;
            }
            var output = new List<MalNewsUnitModel>();
            var raw = await GetRequestResponse();
            if (string.IsNullOrEmpty(raw))
                return null;
            var doc = new HtmlDocument();
            doc.LoadHtml(raw);
            switch (_mode)
            {
                case ArticlePageWorkMode.Articles:
                    foreach (var featuredNewsUnit in doc.WhereOfDescendantsWithClass("div", "featured-pickup-unit"))
                    {
                        try
                        {
                            var current = new MalNewsUnitModel();
                            var img = featuredNewsUnit.Descendants("a").First();
                            var imgUrl = img.Attributes["data-bg"].Value;
                            if (!imgUrl.Contains("questionmark"))
                            {
                                imgUrl = Regex.Replace(imgUrl, @"\/r\/\d+x\d+", "");
                                current.ImgUrl = imgUrl.Substring(0, imgUrl.IndexOf('?'));
                            }
                            current.Url = img.Attributes["href"].Value;
                            current.Highlight = WebUtility.HtmlDecode(featuredNewsUnit.Descendants("p").First().InnerText.Trim());
                            current.Title = WebUtility.HtmlDecode(img.InnerText.Trim());
                            if(current.Title.ToLower().Contains("giveaway")) // emm I'll pass on these
                                continue;
                            var infoDiv = featuredNewsUnit.FirstOfDescendantsWithClass("div", "information");
                            var infoDivsParagraphs = infoDiv.Descendants("p").ToList();
                            current.Author = WebUtility.HtmlDecode(infoDivsParagraphs[0].InnerText.Trim());
                            current.Views = WebUtility.HtmlDecode(infoDivsParagraphs[1].InnerText.Trim());
                            current.Tags = "New";

                            output.Add(current);
                        }
                        catch (Exception)
                        {

                        }
                    }
                    foreach (var newsUnit in doc.WhereOfDescendantsWithClass("div", "news-unit clearfix"))
                    {
                        try
                        {
                            var current = new MalNewsUnitModel();
                            var img = newsUnit.Descendants("a").First();
                            current.Url = img.Attributes["href"].Value;
                            try
                            {
                                current.ImgUrl = img.Descendants("img").First().Attributes["data-src"].Value;
                            }
                            catch (Exception)
                            {
                                //html here is messy, there may be change here soon
                            }
                            var contentDivs = newsUnit.Descendants("div").ToList();
                            current.Title =
                                WebUtility.HtmlDecode(contentDivs[0].Descendants("p").First().InnerText.Trim());
                            current.Highlight = WebUtility.HtmlDecode(contentDivs[1].InnerText.Trim());
                            var infos = contentDivs[2].Descendants("p").ToList();
                            current.Author = infos[0].InnerText.Trim();
                            current.Views = infos[1].InnerText.Trim();
                            try
                            {
                                current.Tags = string.Join(", ",
                                    contentDivs[3].Descendants("a").Select(node => node.InnerText.Trim()));
                            }
                            catch (Exception)
                            {
                                //no tags
                            }
                            current.Type = MalNewsType.Article;
                            output.Add(current);
                        }
                        catch (Exception)
                        {
                            //hatml
                        }
                    }

                    break;
                case ArticlePageWorkMode.News:
                    foreach (var newsUnit in doc.WhereOfDescendantsWithClass("div", "news-unit clearfix rect"))
                    {
                        try
                        {
                            var current = new MalNewsUnitModel();
                            var img = newsUnit.Descendants("a").First();
                            current.Url = img.Attributes["href"].Value;
                            try
                            {
//.........这里部分代码省略.........
开发者ID:Mordonus,项目名称:MALClient,代码行数:101,代码来源:MalArticlesIndexQuery.cs


注:本文中的HtmlAgilityPack.HtmlDocument.WhereOfDescendantsWithClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。