Esempio n. 1
0
        /// <summary>
        /// 找到最近的一个 包括 最多 a 的
        /// </summary>
        /// <param name="currentXElement"></param>
        /// <param name="PossiblyResultElements">可以的结果,找到级别最数最大并且包括a原素最多的Href</param>
        /// <param name="LayerIndex">层次 数字越大,层次越深</param>
        /// <param name="CurrentPossiblyResultElement">当前结果对像用于向下传递</param>
        public static void AnalyseMaxATagNearest(HtmlNode currentXElement, List <PossiblyResultElement> PossiblyResultElements, int LayerIndex, PossiblyResultElement CurrentPossiblyResultElement)
        {
            //要查找的原素名
            string tagname = "a";

            //没有原素直接返回
            if (currentXElement == null || !currentXElement.HasChildNodes)
            {
                return;
            }
            //对子原素进行循环
            //如果有子原素将一直循环到最后一层
            foreach (HtmlNode el in currentXElement.ChildNodes)
            {
                PossiblyResultElement reslut = new PossiblyResultElement()
                {
                    LayerIndex = LayerIndex,
                    // CurrentElement = el,
                    CurrnetHtmlElement   = el,
                    ParentPossiblyResult = CurrentPossiblyResultElement,
                };
                //添加到集合中
                PossiblyResultElements.Add(reslut);
                #region 开始查找 指定标签的 a 原素
                if (el.Name == tagname)
                {
                    //如果找到了 指定标识则+1
                    reslut.ContainTagNum++;
                    continue;
                }
                #endregion
                int k = LayerIndex + 1;
                AnalyseMaxATagNearest(el, PossiblyResultElements, k, reslut);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 找到最近的一个 包括 最多 a 的
        /// </summary>
        /// <param name="currentXElement"></param>
        /// <param name="PossiblyResultElements">可以的结果,找到级别最数最大并且包括a原素最多的Href</param>
        /// <param name="LayerIndex">层次 数字越大,层次越深</param>
        /// <param name="CurrentPossiblyResultElement">当前结果对像用于向下传递</param>
        public static void AnalyseMaxATagNearest(XElement currentXElement, List <PossiblyResultElement> PossiblyResultElements, int LayerIndex, PossiblyResultElement CurrentPossiblyResultElement)
        {
            //要查找的原素名
            string tagname = "a";

            //对子原素进行循环
            //如果有子原素将一直循环到最后一层
            foreach (XElement el in currentXElement.Elements())
            {
                PossiblyResultElement reslut = new PossiblyResultElement()
                {
                    LayerIndex           = LayerIndex,
                    CurrentElement       = el,
                    ParentPossiblyResult = CurrentPossiblyResultElement,
                };
                //添加到集合中
                PossiblyResultElements.Add(reslut);
                #region 开始查找 指定标签的 a 原素
                if (el.Name == tagname)
                {
                    //如果找到了 指定标识则+1
                    reslut.ContainTagNum++;
                    continue;
                }
                #endregion
                LayerIndex = LayerIndex + 1;
                AnalyseMaxATagNearest(el, PossiblyResultElements, LayerIndex, reslut);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Dispose()
 {
     CurrnetHtmlElement = null;
     if (ParentPossiblyResult != null)
     {
         ParentPossiblyResult.Dispose();
     }
     ParentPossiblyResult = null;
 }