Exemplo n.º 1
0
        /// <summary>
        /// Select elements
        /// </summary>
        /// <param name="elementSelector"></param>
        /// <returns></returns>
        protected ISelectable SelectElements(BaseElementSelector elementSelector)
        {
            var elementIterator = Elements;

            if (!elementSelector.HasAttribute())
            {
                List <HtmlAgilityPack.HtmlNode> resultElements = new List <HtmlAgilityPack.HtmlNode>();
                foreach (var element in elementIterator)
                {
                    HtmlAgilityPack.HtmlNode         node           = CheckElementAndConvert(element);
                    IList <HtmlAgilityPack.HtmlNode> selectElements = elementSelector.SelectElements(node);
                    resultElements.AddRange(selectElements);
                }
                return(new HtmlNode(resultElements));
            }
            else
            {
                // has attribute, consider as plaintext
                List <string> resultStrings = new List <string>();
                foreach (var element in elementIterator)
                {
                    HtmlAgilityPack.HtmlNode node       = CheckElementAndConvert(element);
                    IList <string>           selectList = elementSelector.SelectList(node);
                    resultStrings.AddRange(selectList);
                }
                return(new PlainText(resultStrings));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Select elements
 /// </summary>
 /// <param name="elementSelector"></param>
 /// <returns></returns>
 protected ISelectable SelectElements(BaseElementSelector elementSelector)
 {
     var elementIterator = Elements;
     if (!elementSelector.HasAttribute())
     {
         List<HtmlAgilityPack.HtmlNode> resultElements = new List<HtmlAgilityPack.HtmlNode>();
         foreach (var element in elementIterator)
         {
             HtmlAgilityPack.HtmlNode node = CheckElementAndConvert(element);
             IList<HtmlAgilityPack.HtmlNode> selectElements = elementSelector.SelectElements(node);
             resultElements.AddRange(selectElements);
         }
         return new HtmlNode(resultElements);
     }
     else
     {
         // has attribute, consider as plaintext
         List<string> resultStrings = new List<string>();
         foreach (var element in elementIterator)
         {
             HtmlAgilityPack.HtmlNode node = CheckElementAndConvert(element);
             IList<string> selectList = elementSelector.SelectList(node);
             resultStrings.AddRange(selectList);
         }
         return new PlainText(resultStrings);
     }
 }