本文整理汇总了C#中HtmlAgilityPack.HtmlNode.GetElementByClassName方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.GetElementByClassName方法的具体用法?C# HtmlNode.GetElementByClassName怎么用?C# HtmlNode.GetElementByClassName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNode
的用法示例。
在下文中一共展示了HtmlNode.GetElementByClassName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractTags
private static ICollection<string> ExtractTags(HtmlNode articleNode)
{
var tagNode = articleNode.GetElementByClassName("tags");
if (tagNode == null)
{
return new List<string>();
}
return HtmlHelpers.ReplaceHtml(tagNode
.InnerText).Split(new[] {", "}, StringSplitOptions.RemoveEmptyEntries);
}
示例2: ExtractViews
private static int ExtractViews(HtmlNode articleNode)
{
var viewsNode = articleNode.GetElementByClassName("views-count_post");
if (viewsNode == null)
{
return -1;
}
return int.Parse(viewsNode.InnerText);
}
示例3: ExtractName
private static string ExtractName(HtmlNode articleNode)
{
return articleNode.GetElementByClassName("post_title").InnerText;
}
示例4: ExtractRating
private static int ExtractRating(HtmlNode articleNode)
{
var ratingNode = articleNode.GetElementByClassName("voting-wjt__counter-score js-score");
if (ratingNode == null)
{
return int.MinValue;
}
var ratingStr = articleNode.InnerText.Replace('–', '-');
int rating;
if (int.TryParse(ratingStr, out rating))
{
return rating;
}
return int.MinValue;
}
示例5: ExtractHabs
private static ICollection<string> ExtractHabs(HtmlNode articleNode)
{
var hubNode = articleNode.GetElementByClassName("hubs");
if (hubNode == null)
{
return new List<string>();
}
return hubNode
.ChildNodes.Where(n => n.Name == "a")
.Select(n => n.InnerText).ToList();
}
示例6: ExtractFavourites
private static int ExtractFavourites(HtmlNode articleNode)
{
var favouritesNode = articleNode.GetElementByClassName("favorite-wjt__counter js-favs_count");
if (favouritesNode == null)
{
return -1;
}
return int.Parse(favouritesNode.InnerText);
}
示例7: ExtractDate
private static DateTime ExtractDate(HtmlNode articleNode)
{
var publishedNode = articleNode.GetElementByClassName("published");
return publishedNode == null ? DateTime.MinValue : HtmlHelpers.ParseHabrFormatDate(publishedNode.InnerText);
}
示例8: ExtractComments
private static List<string> ExtractComments(HtmlNode articleNode)
{
var commentsNode = articleNode.GetElementByClassName("comments");
if (commentsNode == null)
{
return new List<string>();
}
var nodes = commentsNode
.GetElementsByClassName("message html_format")
.SelectMany(n => n.ChildNodes).ToArray();
foreach (var node in nodes.Where(node => node.Name != "#text"))
{
node.Remove();
}
return nodes.Select(n => HtmlHelpers.ReplaceHtml(n.InnerText))
.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
}
示例9: ExtractAuthor
private static string ExtractAuthor(HtmlNode articleNode)
{
var authorNode = articleNode.GetElementByClassName("author-info__name");
return authorNode == null ? string.Empty : HtmlHelpers.ReplaceHtml(authorNode.InnerText);
}