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


C# IElement.Descendents方法代码示例

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


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

示例1: RemoveNavigation

        protected override void RemoveNavigation(IElement element)
        {
            base.RemoveBloat(element);

            var toRemove = (from e in element.Descendents<IElement>()
                            where e.LocalName == "a"
                            where LinksToRemove.Any(x => x == e.Text().Trim())
                            select e).ToList();

            foreach (IElement e in toRemove)
            {
                e.Remove();
            }
        }
开发者ID:Mitch528,项目名称:WebNovelConverter,代码行数:14,代码来源:NovelsNaoSource.cs

示例2: ParseChapter

        protected virtual WebNovelChapter ParseChapter(IElement rootElement, CancellationToken token = default(CancellationToken))
        {
            WebNovelChapter chapter = new WebNovelChapter();

            IElement element = rootElement.WhereHasClass(PostClasses).LastOrDefault()
                ?? rootElement.Descendents<IElement>().FirstOrDefault(p => p.LocalName == "article");

            if (element != null)
                RemoveBloat(element);

            IElement nextChapterElement = (from e in rootElement?.Descendents<IElement>() ?? new List<IElement>()
                                           where e.LocalName == "a"
                                           let text = e.Text()
                                           let a = NextChapterNames.FirstOrDefault(p => text.IndexOf(p, StringComparison.OrdinalIgnoreCase) >= 0)
                                           where a != null
                                           orderby NextChapterNames.IndexOf(a)
                                           select e).FirstOrDefault();

            if (nextChapterElement != null)
            {
                chapter.NextChapterUrl = nextChapterElement.GetAttribute("href");
            }

            if (element != null)
            {
                chapter.Content = element.InnerHtml;
            }
            else
            {
                chapter.Content = "No Content";
            }

            return chapter;
        }
开发者ID:Mitch528,项目名称:WebNovelConverter,代码行数:34,代码来源:BlogspotSource.cs

示例3: RemoveScriptStyleElements

        protected virtual void RemoveScriptStyleElements(IElement element)
        {
            var elements = from e in element.Descendents<IElement>()
                           where e.LocalName == "script" || e.LocalName == "style"
                           select e;

            foreach (IElement e in elements.ToList())
            {
                e.Remove();
            }
        }
开发者ID:Mitch528,项目名称:WebNovelConverter,代码行数:11,代码来源:WordPressSource.cs

示例4: RemoveNavigation

        protected virtual void RemoveNavigation(IElement element)
        {
            var navElements = from e in element.Descendents<IElement>()
                              where e.LocalName == "a"
                              let text = e.Text()
                              where NavigationNames.Any(p => text.IndexOf(p, StringComparison.OrdinalIgnoreCase) >= 0)
                              select e;

            foreach (IElement e in navElements.ToList())
            {
                e.Remove();
            }
        }
开发者ID:Mitch528,项目名称:WebNovelConverter,代码行数:13,代码来源:WordPressSource.cs

示例5: ParseChapter

        protected virtual WebNovelChapter ParseChapter(IElement rootElement, CancellationToken token = default(CancellationToken))
        {
            IElement articleElement = rootElement.Descendents<IElement>().FirstOrDefault(p => p.LocalName == "article");
            IElement element = rootElement.FirstWhereHasClass(PostClasses) ?? articleElement;

            if (element != null)
                RemoveBloat(element);

            IElement chapterNameElement = rootElement.FirstWhereHasClass(TitleClasses);

            if (element != null && chapterNameElement == null)
            {
                chapterNameElement = (from e in element.Descendents<IElement>()
                                      where e.LocalName == "h1" || e.LocalName == "h2"
                                        || e.LocalName == "h3" || e.LocalName == "h4"
                                      select e).FirstOrDefault();
            }
            else
            {
                IElement chNameLinkElement = (from e in chapterNameElement.Descendents<IElement>()
                                              where e.LocalName == "a"
                                              select e).FirstOrDefault();

                if (chNameLinkElement != null)
                    chapterNameElement = chNameLinkElement;
            }

            IElement nextChapterElement = (from e in articleElement?.Descendents<IElement>() ?? rootElement.Descendents<IElement>()
                                           where e.LocalName == "a"
                                           let text = e.Text()
                                           let a = NextChapterNames.FirstOrDefault(p => text.IndexOf(p, StringComparison.OrdinalIgnoreCase) >= 0)
                                           where a != null || (e.HasAttribute("rel") && e.GetAttribute("rel") == "next")
                                           let index = NextChapterNames.IndexOf(a)
                                           let o = index >= 0 ? index : int.MaxValue
                                           orderby o
                                           select e).FirstOrDefault();

            WebNovelChapter chapter = new WebNovelChapter();
            if (nextChapterElement != null)
            {
                chapter.NextChapterUrl = nextChapterElement.GetAttribute("href");
            }

            if (element != null)
            {
                RemoveNavigation(element);
                RemoveScriptStyleElements(element);

                chapter.ChapterName = chapterNameElement?.Text()?.Trim();
                chapter.Content = element.InnerHtml;
            }
            else
            {
                chapter.Content = "No Content";
            }

            return chapter;
        }
开发者ID:Mitch528,项目名称:WebNovelConverter,代码行数:58,代码来源:WordPressSource.cs

示例6: RemoveTables

 protected virtual void RemoveTables(IElement element)
 {
     element.Descendents<IElement>().Where(p => p.LocalName == "table").ToList().ForEach(p => p.Remove());
 }
开发者ID:Mitch528,项目名称:WebNovelConverter,代码行数:4,代码来源:BakaTsukiSource.cs


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