Exemplo n.º 1
0
        protected string handleSelector(selectorBlock Selector, AngleSharp.Dom.IElement Dom)
        {
            if (Selector.Text != null)
            {
                return(applyFilters(Selector.Text, Selector.Filters));
            }
            string value = null;

            if (Selector.Selector != null)
            {
                AngleSharp.Dom.IElement selection = Dom.QuerySelector(Selector.Selector);
                if (selection == null)
                {
                    throw new Exception(string.Format("Selector \"{0}\" didn't match {1}", Selector.Selector, Dom.OuterHtml));
                }
                if (Selector.Remove != null)
                {
                    foreach (var i in selection.QuerySelectorAll(Selector.Remove))
                    {
                        i.Remove();
                    }
                }
                if (Selector.Attribute != null)
                {
                    value = selection.GetAttribute(Selector.Attribute);
                }
                else
                {
                    value = selection.TextContent;
                }
            }
            return(applyFilters(value, Selector.Filters));;
        }
Exemplo n.º 2
0
        protected string handleSelector(selectorBlock Selector, IElement Dom)
        {
            if (Selector.Text != null)
            {
                return(applyFilters(Selector.Text, Selector.Filters));
            }

            IElement selection = Dom;
            string   value     = null;

            if (Selector.Selector != null)
            {
                selection = Dom.QuerySelector(Selector.Selector);
                if (selection == null)
                {
                    throw new Exception(string.Format("Selector \"{0}\" didn't match {1}", Selector.Selector, Dom.OuterHtml));
                }
            }

            if (Selector.Remove != null)
            {
                foreach (var i in selection.QuerySelectorAll(Selector.Remove))
                {
                    i.Remove();
                }
            }

            if (Selector.Case != null)
            {
                foreach (var Case in Selector.Case)
                {
                    if (selection.Matches(Case.Key) || selection.QuerySelector(Case.Key) != null)
                    {
                        value = Case.Value;
                        break;
                    }
                }
                if (value == null)
                {
                    throw new Exception(string.Format("None of the case selectors \"{0}\" matched {1}", string.Join(",", Selector.Case), selection.OuterHtml));
                }
            }
            else if (Selector.Attribute != null)
            {
                value = selection.GetAttribute(Selector.Attribute);
            }
            else
            {
                value = selection.TextContent;
            }

            return(applyFilters(value, Selector.Filters));;
        }
Exemplo n.º 3
0
        protected string handleSelector(selectorBlock Selector, IElement Dom)
        {
            if (Selector.Text != null)
            {
                return applyFilters(Selector.Text, Selector.Filters);
            }

            IElement selection = Dom;
            string value = null;

            if (Selector.Selector != null)
            {
                selection = QuerySelector(Dom, Selector.Selector);
                if (selection == null)
                {
                    throw new Exception(string.Format("Selector \"{0}\" didn't match {1}", Selector.Selector, Dom.OuterHtml));
                }
            }

            if (Selector.Remove != null)
            {
                foreach(var i in selection.QuerySelectorAll(Selector.Remove))
                {
                    i.Remove();
                }
            }

            if (Selector.Case != null)
            {
                foreach(var Case in Selector.Case)
                {
                    if (selection.Matches(Case.Key) || QuerySelector(selection, Case.Key) != null)
                    {
                        value = Case.Value;
                        break;
                    }
                }
                if(value == null)
                    throw new Exception(string.Format("None of the case selectors \"{0}\" matched {1}", string.Join(",", Selector.Case), selection.OuterHtml));
            }
            else if (Selector.Attribute != null)
            {
                value = selection.GetAttribute(Selector.Attribute);
            }
            else
            {
                value = selection.TextContent;
            }
                
            return applyFilters(value, Selector.Filters); ;
        }