예제 #1
0
        public IEnumerable <HtmlElement> GetElement(IEnumerable <HtmlElement> source, string element)
        {
            if (source == null)
            {
                throw new ArgumentException(nameof(HtmlElement));
            }
            if (!_htmlConfig.IsHtmlElement(element))
            {
                throw new ArgumentException("element is invalid");
            }

            var allElements = HtmlHelpers.GetAllElements(source);

            return(allElements.Where(e => e.ElementName == element));
        }
예제 #2
0
        public Maybe <HtmlElement> GetElementById(IEnumerable <HtmlElement> source, string id)
        {
            if (source == null)
            {
                throw new ArgumentException(nameof(HtmlElement));
            }

            var eleList = HtmlHelpers.GetAllElements(source);

            foreach (var element in eleList)
            {
                if (!element.Attributes.ContainsKey("id"))
                {
                    continue;
                }
                if (element.Attributes["id"].Contains(id))
                {
                    return(new Maybe <HtmlElement>(element));
                }
            }

            return(new Maybe <HtmlElement>());
        }
예제 #3
0
        public IEnumerable <HtmlElement> GetElementByClass(IEnumerable <HtmlElement> source, string className)
        {
            if (source == null)
            {
                throw new ArgumentException(nameof(HtmlElement));
            }

            var eleList          = HtmlHelpers.GetAllElements(source);
            var selectedElements = new List <HtmlElement>();

            foreach (var element in eleList)
            {
                if (!element.Attributes.ContainsKey("class"))
                {
                    continue;
                }
                if (element.Attributes["class"].Contains(className))
                {
                    selectedElements.Add(element);
                }
            }

            return(selectedElements);
        }