Exemplo n.º 1
0
        public static string QuerySelectorAttributeOrHtml(this HtmlNode htmlNode, SelectorSettings settings)
        {
            HtmlNode selectedNode = htmlNode.QuerySelector(settings.Selector);

            if (selectedNode == null)
            {
                throw new ApplicationException($"Error: Selector {settings.Selector} failed to find any elements.");
            }

            if (string.IsNullOrWhiteSpace(settings.Attribute))
            {
                return(selectedNode.InnerHtml);
            }

            return(selectedNode.Attributes[settings.Attribute].Value);
        }
Exemplo n.º 2
0
        public static string QuerySelectorAttributeOrText(this HtmlNode htmlNode, SelectorSettings settings)
        {
            HtmlNode selectedNode = htmlNode.QuerySelector(settings.Selector);

            if (selectedNode == null)
            {
                throw new ApplicationException($"Error: Selector {settings.Selector} failed to find any elements.");
            }

            // Hack: Add physical newlines to <br />s to make date parsing easier for LastUpdated / Published.
            // Also means that we match Firefox functionality.
            foreach (HtmlNode nextNode in htmlNode.QuerySelectorAll("br"))
            {
                nextNode.InnerHtml = "\n";
            }

            if (string.IsNullOrWhiteSpace(settings.Attribute))
            {
                return(selectedNode.InnerText);
            }

            return(selectedNode.Attributes[settings.Attribute].Value);
        }