本文整理汇总了C#中HtmlAgilityPack.HtmlNode.GetElementsOfType方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.GetElementsOfType方法的具体用法?C# HtmlNode.GetElementsOfType怎么用?C# HtmlNode.GetElementsOfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNode
的用法示例。
在下文中一共展示了HtmlNode.GetElementsOfType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFacets
public override IEnumerable<SEOAnalysisFacet> GetFacets(Webpage webpage, HtmlNode document, string analysisTerm)
{
var elements = document.GetElementsOfType("h1");
if (elements.Count() > 1)
yield return
GetFacet("Document contains multiple H1 tags", SEOAnalysisStatus.Error,
"There should only be one H1 tag in a document.");
}
示例2: GetFacets
public override IEnumerable<SEOAnalysisFacet> GetFacets(Webpage webpage, HtmlNode document, string analysisTerm)
{
var images = document.GetElementsOfType("img").ToList();
IEnumerable<HtmlNode> imagesWithoutAlt = images.FindAll(node => !node.Attributes.Contains("alt"));
string hasNotGotAnAltTag = _stringResourceProvider.GetValue("Admin SEO Analysis Has not got", " has not got an alt tag");
yield return GetFacet(_stringResourceProvider.GetValue("Admin SEO Analysis Has not got alt tags", "All images have alt tags"),
!imagesWithoutAlt.Any()
? SEOAnalysisStatus.Success
: SEOAnalysisStatus.Error,
imagesWithoutAlt.Select(node => node.GetAttributeValue("src", "") + hasNotGotAnAltTag).ToArray());
}
示例3: GetFacets
public override IEnumerable<SEOAnalysisFacet> GetFacets(Webpage webpage, HtmlNode document, string analysisTerm)
{
var subheadings = document.GetElementsOfType("h2").ToList();
if (!subheadings.Any())
{
yield return GetFacet("Subheadings", SEOAnalysisStatus.CanBeImproved, "The page contains no subheadings (i.e. h2 tags)");
yield break;
}
var matchingNodes = subheadings.FindAll(node => node.InnerHtml.Contains(analysisTerm, StringComparison.OrdinalIgnoreCase));
if (!matchingNodes.Any())
yield return
GetFacet("Subheadings", SEOAnalysisStatus.CanBeImproved, string.Format("{0} of the {1} subheadings contain the target term", matchingNodes.Count(), subheadings.Count()));
else
yield return
GetFacet("Subheadings", SEOAnalysisStatus.Success, string.Format("{0} of the {1} subheadings contain the target term", matchingNodes.Count(), subheadings.Count()));
}
示例4: GetFacets
public override IEnumerable<SEOAnalysisFacet> GetFacets(Webpage webpage, HtmlNode document, string analysisTerm)
{
var paragraphs = document.GetElementsOfType("p").ToList();
if (!paragraphs.Any())
{
yield return
GetFacet("Body Content", SEOAnalysisStatus.Error,
string.Format("Body content contains no paragraphs of text"));
yield break;
}
if (paragraphs[0].InnerText.Contains(analysisTerm, StringComparison.OrdinalIgnoreCase))
{
yield return GetFacet("Body Content", SEOAnalysisStatus.Success,
string.Format("The first paragraph contains the term '{0}'", analysisTerm));
}
else
{
yield return GetFacet("Body Content", SEOAnalysisStatus.CanBeImproved,
string.Format("The first paragraph does not contain the term '{0}'", analysisTerm));
}
}