本文整理汇总了C#中IElement.FirstWhereHasClass方法的典型用法代码示例。如果您正苦于以下问题:C# IElement.FirstWhereHasClass方法的具体用法?C# IElement.FirstWhereHasClass怎么用?C# IElement.FirstWhereHasClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IElement
的用法示例。
在下文中一共展示了IElement.FirstWhereHasClass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPagedChapterUrls
protected virtual IEnumerable<string> GetPagedChapterUrls(IElement rootElement)
{
var pagElements = rootElement.FirstWhereHasClass(PaginationClasses, e => e.LocalName == "div")
?.Descendents<IElement>();
pagElements = pagElements?.Where(p => p.LocalName == "a");
if (pagElements == null)
return new List<string>();
return pagElements.Select(p => p.GetAttribute("href"));
}
示例2: 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;
}