コード例 #1
0
        private string GetContentFromParsingCommand(string content, ParseCommand parsingCommand)
        {
            switch (parsingCommand.Type)
            {
            case ParseCommandType.Css:
                return(GetContentFromCssParsingCommand(content, parsingCommand));

            case ParseCommandType.RegEx:
                return(GetContentFromRegExParsingCommand(content, parsingCommand));
            }

            return(string.Empty);
        }
コード例 #2
0
        private string GetContentFromRegExParsingCommand(string content, ParseCommand parsingCommand)
        {
            var match = Regex.Match(content, parsingCommand.Selector);

            var targetIndex = parsingCommand.TargetIndex ?? 1;

            if (match != null && match.Groups.Count > targetIndex)
            {
                return(match.Groups[targetIndex].Value);
            }

            return(string.Empty);
        }
コード例 #3
0
        private IEnumerable <string> GetContentByParsingCommands(
            string content,
            ParseCommand parsingCommand,
            ParseCommand parentParsingCommand = null
            )
        {
            if (parsingCommand == null)
            {
                return(GetValuesFromParentParsingCommand(content, parentParsingCommand));
            }

            content = GetContentFromParsingCommand(content, parsingCommand);

            return(GetContentByParsingCommands(
                       content,
                       parsingCommand.ContentParsingCommand,
                       parsingCommand
                       ));
        }
コード例 #4
0
 private string GetContentFromCssParsingCommand(string content, ParseCommand parsingCommand)
 {
     return(CQ.Create(content)[parsingCommand.Selector].RenderSelection());
 }
コード例 #5
0
        private IEnumerable <string> GetValuesFromParentCssParsingCommand(string content, ParseCommand parsingCommand)
        {
            var document        = CQ.Create(content);
            var targetAttribute = parsingCommand.Attribute;

            return(document.Select(
                       part =>
                       string.IsNullOrEmpty(targetAttribute) ? part.InnerText
            : part.Attributes[targetAttribute]
                       ));
        }
コード例 #6
0
        private IEnumerable <string> GetValuesFromParentParsingCommand(string content, ParseCommand parsingCommand)
        {
            switch (parsingCommand.Type)
            {
            case ParseCommandType.Css:
                return(GetValuesFromParentCssParsingCommand(content, parsingCommand));
            }

            return(new[] { content });
        }