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


C# HtmlNode.Ancestors方法代码示例

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


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

示例1: IndentationFor

 private string IndentationFor(HtmlNode node)
 {
     int length = node.Ancestors("ol").Count() + node.Ancestors("ul").Count();
     return node.ParentNode.Name.ToLowerInvariant() == "li" && node.ParentNode.FirstChild != node
         ? new string(' ', length * 4)
         : Environment.NewLine + Environment.NewLine;
 }
开发者ID:JuanAr,项目名称:reversemarkdown-net,代码行数:7,代码来源:P.cs

示例2: AnalyzeNode

 private string AnalyzeNode(HtmlNode node)
 {
     string curText = node.InnerText;
     int wordLength = Extractor.WordLength(curText);
     int wordCount = Extractor.WordCount(curText);
     int upperCaseCount = Extractor.UpperCaseCount(curText);
     bool finishedSentence = Extractor.ContainsPunctuation(curText);
     if (wordCount == 0)
     {
         return "";
     }
     bool isLink = node.Ancestors("a").ToList().Count > 0;
     double linkRatio = 0;
     int averageSentenceLength = Extractor.SentenceLength(curText);
     int nrOfSentences = Extractor.NrOfSentences(curText);
     if (isLink)
     {
         HtmlNode parentNode = node.ParentNode;
         string clazz = parentNode.Attributes["class"] == null ? null : parentNode.Attributes["class"].Value;
         while (parentNode.Name == "a" || (clazz != null && clazz.IndexOf("x-nc-sel") != -1))
         {
             parentNode = parentNode.ParentNode;
             clazz = parentNode.Attributes["class"] == null ? null : parentNode.Attributes["class"].Value;
         }
         string parentText = parentNode.InnerText;
         int totalWords = Extractor.WordCount(parentText);
         linkRatio = ((double)wordCount) / ((double)totalWords);
     }
     return String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}", wordLength, wordCount,
         nrOfSentences, averageSentenceLength, isLink ? "Yes" : "No", linkRatio.ToString("##0.00###", CultureInfo.CreateSpecificCulture("en-GB")), upperCaseCount, finishedSentence ? "Yes" : "No" );
 }
开发者ID:erik-lundgren,项目名称:datacollect,代码行数:31,代码来源:Analyzer.cs

示例3: TryToGetCity

        // try to find the city of hall by xPath
        private static string TryToGetCity(HtmlNode htmlNode)
        {
            var td = htmlNode.Ancestors("td").Where(t => t.GetAttributeValue("hallslistwrap", "") != null).ToList();

            if (td.First() == null) return null;

            const string xPath1 = @"../../../../preceding::tr[1]//h5"; // xpath to City Name
            var h5 = td.First().SelectSingleNode(xPath1);

            return h5?.InnerHtml;
        }
开发者ID:MishaKav,项目名称:BravoCrawler,代码行数:12,代码来源:Program.cs

示例4: IndentationFor

 private string IndentationFor(HtmlNode node)
 {
     int length = node.Ancestors("ol").Count() + node.Ancestors("ul").Count();
     return new string(' ', Math.Max(length-1,0));
 }
开发者ID:huoxudong125,项目名称:reversemarkdown-net,代码行数:5,代码来源:Li.cs

示例5: AlreadyItalic

		private bool AlreadyItalic(HtmlNode node)
		{
			return node.Ancestors("i").Count() > 0 || node.Ancestors("em").Count() > 0;
		}
开发者ID:nashdot,项目名称:reversemarkdown-net,代码行数:4,代码来源:Em.cs

示例6: ProcessNode

 private void ProcessNode(HtmlNode node)
 {
     Node n = new Node();
     n.text = node.InnerText;
     n.wordCount = WordCount(node.InnerText);
     HtmlNodeCollection linkNodes = node.SelectNodes("../a");
     List<HtmlNode> ancestors = node.Ancestors("a").ToList();
     n.isLink = ancestors.Count > 0; // represents the element itself being inside some hierarchy that contains some number of a tags
     double linkCount = n.isLink ? 1 : 0;
     if (linkNodes != null)
     {
         linkCount += linkNodes.Count;
     }
     n.linkRatio = linkCount / n.wordCount;
     nodes.Add(n);
 }
开发者ID:erik-lundgren,项目名称:datacollect,代码行数:16,代码来源:Extractor.cs

示例7: AlreadyBold

		private bool AlreadyBold(HtmlNode node)
		{
			return node.Ancestors("strong").Count() > 0 || node.Ancestors("b").Count() > 0;
		}
开发者ID:nashdot,项目名称:reversemarkdown-net,代码行数:4,代码来源:Strong.cs


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