本文整理汇总了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();
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例6: RemoveTables
protected virtual void RemoveTables(IElement element)
{
element.Descendents<IElement>().Where(p => p.LocalName == "table").ToList().ForEach(p => p.Remove());
}