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


C# HtmlNode.FirstOfDescendantsWithClass方法代码示例

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


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

示例1: ParseInboxHtmlToMalMessage

        private MalMessageModel ParseInboxHtmlToMalMessage(HtmlNode msgNode, bool read)
        {
            var current = new MalMessageModel();
            current.Sender = msgNode.FirstOfDescendantsWithClass("div", "mym mym_user").InnerText.Trim();
            current.Target = Credentials.UserName;
            var contentNode = msgNode.FirstOfDescendantsWithClass("div", "mym mym_subject");
            current.Subject =
                WebUtility.HtmlDecode(contentNode.Descendants("a").First().ChildNodes[0].InnerText.Trim().Trim('-'));
            current.Content = WebUtility.HtmlDecode(contentNode.Descendants("span").First().InnerText.Trim());
            current.Id =
                contentNode.FirstOfDescendantsWithClass("a", "subject-link").Attributes["href"].Value.Split('=')
                    .Last();
            current.Date = msgNode.FirstOfDescendantsWithClass("span", "mym_date").InnerText.Trim();
            current.IsRead = read;

            var ids =
                msgNode.FirstOfDescendantsWithClass("span", "mym_actions").Descendants("a").First().Attributes["href"]
                    .Value.Split('=');
            current.ThreadId = ids[3].Substring(0, ids[3].IndexOf('&'));
            current.ReplyId = ids[2].Substring(0, ids[3].IndexOf('&'));
            return current;
        }
开发者ID:Mordonus,项目名称:MALClient,代码行数:22,代码来源:MalMessagesQuery.cs

示例2: ParseFromHtml

        public static SeasonalAnimeData ParseFromHtml(HtmlNode htmlNode,int index,bool parseDate = true)
        {
            if (htmlNode.Attributes["class"]?.Value != HtmlClassMgr.ClassDefs["#Seasonal:entryNode:class"])
                return null;

            var imageNode =
                htmlNode.FirstOfDescendantsWithClass("div", "image lazyload");
            var link = imageNode.ChildNodes.First(node => node.Name == "a").Attributes["href"].Value;
            var img = imageNode.Attributes["data-bg"].Value;
            var scoreTxt =
                htmlNode.Descendants("span")
                    .First(
                        node =>
                            node.Attributes.Contains("class") &&
                            node.Attributes["class"].Value ==
                            HtmlClassMgr.ClassDefs["#Seasonal:entryNode:score:class"])
                    .InnerText;
            var infoNode =
                htmlNode.Descendants("div")
                    .First(
                        node =>
                            node.Attributes.Contains("class") &&
                            node.Attributes["class"].Value ==
                            HtmlClassMgr.ClassDefs["#Seasonal:entryNode:info:class"]);
            int day = -1;
            string airStartDate = null;
            if(parseDate)
                try
                {
                    var date = infoNode.ChildNodes[1].InnerText.Trim().Substring(0, 13).Replace(",", "");
                    var dateObj = DateTime.Parse(date);
                    day = (int)dateObj.DayOfWeek;
                    airStartDate = dateObj.ToString("yyyy-MM-dd");
                    day++;
                }
                catch (Exception)
                {
                    day = -1;
                }

            float score;
            if (!float.TryParse(scoreTxt, out score))
                score = 0;
            return new SeasonalAnimeData
            {
                Title = WebUtility.HtmlDecode(imageNode.InnerText.Trim()),
                //there are some \n that we need to get rid of
                Id = int.Parse(link.Substring(8).Split('/')[2]), //extracted from anime link
                ImgUrl = img, // from image style attr it's between ( )
                Score = score, //0 for N/A
                Episodes =
                    htmlNode.Descendants("div")
                        .First(
                            node =>
                                node.Attributes.Contains("class") &&
                                node.Attributes["class"].Value ==
                                HtmlClassMgr.ClassDefs["#Seasonal:entryNode:eps:class"])
                        .Descendants("a")
                        .First()
                        .InnerText.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries)[0],
                Index = index,
                Genres = htmlNode.Descendants("div").First(node =>
                        node.Attributes.Contains("class") &&
                        node.Attributes["class"].Value ==
                        HtmlClassMgr.ClassDefs["#Seasonal:entryNode:genres:class"])
                    .InnerText
                    .Replace('\n', ';')
                    .Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries)
                    .Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim())
                    .ToList(),
                AirDay = day,
                AirStartDate = airStartDate
            };
        }
开发者ID:Mordonus,项目名称:MALClient,代码行数:74,代码来源:AnimeSeasonalQuery.cs

示例3: ParseOutboxHtmlToMalMessage

 private MalMessageModel ParseOutboxHtmlToMalMessage(HtmlNode msgNode)
 {
     var current = new MalMessageModel();
     current.Target = msgNode.FirstOfDescendantsWithClass("div", "mym mym_user").InnerText.Trim();
     current.Sender = Credentials.UserName;
     var contentNode = msgNode.FirstOfDescendantsWithClass("div", "mym mym_subject");
     current.Subject =
         WebUtility.HtmlDecode(contentNode.Descendants("a").First().ChildNodes[0].InnerText.Trim().Trim('-'));
     current.Content = WebUtility.HtmlDecode(contentNode.Descendants("span").First().InnerText.Trim());
     current.Date = msgNode.FirstOfDescendantsWithClass("span", "mym_date").InnerText.Trim();
     current.IsMine = true;
     return current;
 }
开发者ID:Mordonus,项目名称:MALClient,代码行数:13,代码来源:MalMessagesQuery.cs


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