예제 #1
0
        public static IEnumerable <HtmlNode> CssSelect(this HtmlNode node, string expression)
        {
            var tokenizer = new CssSelectorTokenizer();
            var tokens    = tokenizer.Tokenize(expression);
            var executor  = new CssSelectorExecutor <HtmlNode>(new List <HtmlNode> {
                node
            }, tokens.ToList(), new AgilityNavigationProvider());

            return(executor.GetElements());
        }
        public void When_execute_css_selector2()
        {
            var tokenizer = new CssSelectorTokenizer();
            var tokens    = tokenizer.Tokenize("div.widget.monthlist");

            Assert.AreEqual(5, tokens.Length);

            var executor = new CssSelectorExecutor <HtmlNode>(html.ChildNodes.ToList(), tokens.ToList(), new AgilityNavigationProvider());

            HtmlNode[] htmlNodes = executor.GetElements();

            Assert.AreEqual(1, htmlNodes.Length);
        }
        public static IEnumerable <HElement> CssSelect(this HElement node, string expression)
        {
            if (string.IsNullOrEmpty(expression))
            {
                return new HElement[] { }
            }
            ;

            var tokenizer = new CssSelectorTokenizer();
            var tokens    = tokenizer.Tokenize(expression);
            var executor  = new CssSelectorExecutor <HElement>(new List <HElement> {
                node
            }, tokens.ToList(), new HElementNavigationProvider());

            return(executor.GetElements());
        }
    }