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


C# HtmlNode.DescendantsAndSelf方法代码示例

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


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

示例1: FromPost

        public static ForumUserEntity FromPost(HtmlNode postNode)
        {
            var user = new ForumUserEntity
            {
                Username =
                    WebUtility.HtmlDecode(
                        postNode.Descendants("dt")
                            .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("author"))
                            .InnerHtml),
                DateJoined =
                   DateTime.Parse(postNode.Descendants("dd")
                        .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("registered"))
                        .InnerHtml)
            };
            var avatarTitle = postNode.Descendants("dd").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("title"));
            var avatarImage = postNode.Descendants("dd").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("title")).Descendants("img").FirstOrDefault();

            if (avatarTitle != null)
            {
                user.AvatarTitle = WebUtility.HtmlDecode(avatarTitle.InnerText).WithoutNewLines().Trim();
            }
            if (avatarImage != null)
            {
                user.AvatarLink = FixPostHtmlImage(avatarImage.OuterHtml);
            }
            user.Id = Convert.ToInt64(postNode.DescendantsAndSelf("td").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("userinfo")).GetAttributeValue("class", string.Empty).Split('-')[1]);
            return user;
        }
开发者ID:jarkkom,项目名称:AwfulMetro,代码行数:28,代码来源:ForumUserEntity.cs

示例2: GetThreadID

        private int GetThreadID(HtmlNode node)
        {
            var threadIDNode = node.DescendantsAndSelf()
                 .Where(value => value.GetAttributeValue("id", "") != null)
                 .FirstOrDefault();

            string id = threadIDNode.GetAttributeValue("id", "").Trim();
            id = id.Replace("thread", "");

            int parsedID = -1;
            int.TryParse(id, out parsedID);
            Awful.Core.Event.Logger.AddEntry(string.Format("SAThread - ThreadID: {0}", id));

            return parsedID;
        }
开发者ID:bootlegrobot,项目名称:awful,代码行数:15,代码来源:SAThreadFactory.cs

示例3: ExtractViewableTextCleaned

        public static string ExtractViewableTextCleaned(HtmlNode root)
        {
            var chunks = new List<string>();

            foreach (var item in root.DescendantsAndSelf())
            {
                if (item.NodeType == HtmlNodeType.Text)
                {
                    if (item.InnerText.Trim() != "")
                    {
                        chunks.Add(item.InnerText.Trim());
                    }
                }
            }
            return String.Join(" ", chunks);
        }
开发者ID:VAmaral,项目名称:SRS,代码行数:16,代码来源:HtmlTextExtractor.cs

示例4: ParseEcrExpress

 private static void ParseEcrExpress(HtmlNode column,EcrModel model)
 {
     var hrefs = column.DescendantsAndSelf().Where(x => x.Name == "a").ToList();
     var index = 0;
     foreach (var hy in hrefs)
     {
         if (hy.InnerText != "")
         {
             if (index == 0)
             {
                 model.Ecr = long.Parse(hy.InnerText);
             }
             else
             {
                 model.ExpressCode = long.Parse(hy.InnerText);
             }
             index++;
         }
        
     }
 }
开发者ID:DrNorton,项目名称:TrineTimeTable,代码行数:21,代码来源:Program.cs

示例5: ParseNameStantion

        private static void ParseNameStantion(HtmlNode column, EcrModel result)
        {
            try
            {
                result.StationImageUrl = column.DescendantsAndSelf().FirstOrDefault(x => x.Name == "img").Attributes.FirstOrDefault().Value;
                result.StationName = column.InnerText.Replace("\r\n      &nbsp;", "").Replace("  ", "");
            }
            catch (Exception e)
            {
                
            }
            


        }
开发者ID:DrNorton,项目名称:TrineTimeTable,代码行数:15,代码来源:Program.cs

示例6: FromPost

        public static ForumUserEntity FromPost(HtmlNode postNode)
        {
            var user = new ForumUserEntity
            {
                Username =
                    WebUtility.HtmlDecode(
                        postNode.Descendants("dt")
                            .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("author"))
                            .InnerHtml)
            };
            var dateTimeNode = postNode.Descendants("dd")
                .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("registered"));
            if (dateTimeNode != null)
            {
                try
                {
                    user.DateJoined = DateTime.Parse(dateTimeNode.InnerHtml);
                }
                catch (Exception)
                {
                    // Parsing failed, so say they joined today.
                    // I blame SA for any parsing failures.
                    user.DateJoined = DateTime.UtcNow;
                }
                
            }
            HtmlNode avatarTitle =
                postNode.Descendants("dd")
                    .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("title"));
            HtmlNode avatarImage =
                postNode.Descendants("dd")
                    .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("title"))
                    .Descendants("img")
                    .FirstOrDefault();

            if (avatarTitle != null)
            {
                user.AvatarTitle = WebUtility.HtmlDecode(avatarTitle.InnerText).WithoutNewLines().Trim();
            }
            if (avatarImage != null)
            {
                user.AvatarLink = avatarImage.GetAttributeValue("src", string.Empty);
            }
            var userIdNode = postNode.DescendantsAndSelf("td")
                .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("userinfo")) ??
                             postNode.DescendantsAndSelf("div")
                    .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("userinfo"));
            if (userIdNode == null) return user;

            var splitString = userIdNode
                .GetAttributeValue("class", string.Empty)
                .Split('-');

            if (splitString.Length >= 2)
            {
                user.Id =
                    Convert.ToInt64(splitString[1]);
            }
            // Remove the UserInfo node after we are done with it, because
            // some forums (FYAD) use it in the body of posts. Why? Who knows!11!1
            userIdNode.Remove();
            return user;
        }
开发者ID:Gluco,项目名称:AwfulMetro,代码行数:63,代码来源:ForumUserEntity.cs

示例7: GetAllInnerTexts

 /// <summary>
 /// Find all inner texts and return a simplified string.
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 protected virtual string GetAllInnerTexts(HtmlNode node)
 {
     return RemoveWhitespace(string.Join(" ", node.DescendantsAndSelf()
             .Select(d => d.InnerText.Replace(Environment.NewLine, " ")))).Trim().ToLowerInvariant();
 }
开发者ID:hermanussen,项目名称:sitecore-html-crawler,代码行数:10,代码来源:HtmlCrawledField.cs

示例8: ParseThreadSeen

        private static ThreadMetadata ParseThreadSeen(this ThreadMetadata thread, HtmlNode node)
        {
            // if the node is null, then we haven't seen this thread, otherwise it's been visited
            var threadSeenNode = node.DescendantsAndSelf()
               .Where(value => value.GetAttributeValue("class", "").Contains("thread seen"))
               .FirstOrDefault();

            bool seen = threadSeenNode == null ? false : true;
            thread.IsNew = !seen;

            // if thread is new, all posts are new, so don't show post count
            if (thread.IsNew)
            {
                thread.NewPostCount = -1;
                thread.ShowPostCount = false;
            }

            // else parse thread count
            else { thread = ParseThreadCount(thread, node); }

            return thread;
        }
开发者ID:jarkkom,项目名称:awfuldotnet,代码行数:22,代码来源:ThreadParser.cs

示例9: ParseThreadSeen

        private void ParseThreadSeen(SAThread thread, HtmlNode node)
        {
            // if the node is null, then we haven't seen this thread, otherwise it's been visited
            var threadSeenNode = node.DescendantsAndSelf()
               .Where(value => value.GetAttributeValue("class", "").Contains("thread seen"))
               .FirstOrDefault();

            bool seen = threadSeenNode == null ? false : true;
            thread.ThreadSeen = seen;

            // if thread is new, all posts are new, so don't show post count
            if (!thread.ThreadSeen)
            {
                thread.NewPostCount = -1;
                thread.ShowPostCount = false;
                Awful.Core.Event.Logger.AddEntry("SAThread - This thread is brand new! Hide the post count.");
            }

            // else parse thread count
            else { this.ParseThreadCount(thread, node); }
        }
开发者ID:bootlegrobot,项目名称:awful,代码行数:21,代码来源:SAThreadFactory.cs

示例10: ParsePostID

        private int ParsePostID(HtmlNode postNode)
        {
            var id = postNode.DescendantsAndSelf()
              .Where(node => node.GetAttributeValue("class", "").Equals("post"))
              .FirstOrDefault();

            int result = -1;

            if (id != null)
            {
                string postID = id.GetAttributeValue("id", "").Replace("post", "");
                int.TryParse(postID, out result);
            }

            return result;
        }
开发者ID:bootlegrobot,项目名称:awful,代码行数:16,代码来源:SAPostFactory.cs

示例11: GetPodcastData

        private Podcast GetPodcastData(HtmlNode node)
        {
            Podcast returnPodcast = new Podcast();

            List<HtmlNode> nodes = new List<HtmlNode>();
            nodes = node.DescendantsAndSelf().ToList<HtmlNode>();

            try { returnPodcast.Title = GetTitle(node.ChildNodes.FindFirst("h3")); }
            catch (Exception) { }

            try { returnPodcast.EpisodeUri = GetEpisodeUri(node.ChildNodes.FindFirst("h3")); }
            catch (Exception) { }

            try { returnPodcast.Uri = GetUri(node.ChildNodes.FindFirst("audio")); }
            catch (Exception) { }

            try { returnPodcast.BibleReference = GetBibleReference(node.SelectSingleNode("p[@class='metadata']")); }
            catch (Exception) { }

            try
            {
                returnPodcast.Description = GetDescription(node,
                                              returnPodcast.BibleReference,
                                              node.SelectSingleNode("p[@class='metadata']").ChildNodes[0].InnerText);
            }
            catch (Exception) { }

            //returnPodcast.Length = GetPodcastLength(returnPodcast.Uri);

            return returnPodcast;
        }
开发者ID:diagonalwalnut,项目名称:MLJPodcast,代码行数:31,代码来源:HomeController.cs


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