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); }
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); }
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 )); }
private string GetContentFromCssParsingCommand(string content, ParseCommand parsingCommand) { return(CQ.Create(content)[parsingCommand.Selector].RenderSelection()); }
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] )); }
private IEnumerable <string> GetValuesFromParentParsingCommand(string content, ParseCommand parsingCommand) { switch (parsingCommand.Type) { case ParseCommandType.Css: return(GetValuesFromParentCssParsingCommand(content, parsingCommand)); } return(new[] { content }); }