public List <string> GetResults(string Txt, string Jpath, T parm) { Txt = Txt?.Trim(); List <String> list = new List <string>(); JToken token = default; if (Txt.StartsWith("{") && Txt.EndsWith("}")) { token = JsonConvert.DeserializeObject(Txt) as JObject; } else if (Txt.StartsWith("[") && Txt.EndsWith("]")) { token = JsonConvert.DeserializeObject(Txt) as JArray; } if (token != null) { JsonParm jsonam = BaseParm.ConvertParm <JsonParm>(parm); var tokens = token.SelectTokens(Jpath); if (tokens?.Count() > 0) { list = (from a in tokens select Convert.ToString(a))?.ToList(); } } return(list); }
public List <string> GetResults(string Txt, string Xpath, T parm) { List <String> list = new List <string>(); HtmlAgilityPack.HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(Txt); var nodes = doc.DocumentNode.SelectNodes(Xpath); XpathPam xpathparm = BaseParm.ConvertParm <XpathPam>(parm); if (nodes?.Count > 0) { foreach (var node in nodes) { //null 校验是否存在 if (xpathparm.InnerHtml) { list.Add(node.InnerHtml); } //非null校验值 else if (!String.IsNullOrEmpty(xpathparm.Attr)) { list.Add(node.Attributes[xpathparm.Attr]?.Value); } else { list.Add(node.InnerText); } } } return(list); }
public string GetResult(string Txt, string Xpath, T parm) { HtmlAgilityPack.HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(Txt); var node = doc.DocumentNode.SelectSingleNode(Xpath); XpathPam xpathparm = BaseParm.ConvertParm <XpathPam>(parm); if (node == null) { return(String.Empty); } //null 校验是否存在 if (xpathparm.InnerHtml) { return(node.InnerHtml); } //非null校验值 else if (!String.IsNullOrEmpty(xpathparm.Attr)) { return(node.Attributes[xpathparm.Attr]?.Value); } else { return(node.InnerText); } }
public bool Check(string Txt, string Xpath, T parm) { HtmlAgilityPack.HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(Txt); var node = doc.DocumentNode.SelectSingleNode(Xpath); XpathPam xpathparm = BaseParm.ConvertParm <XpathPam>(parm); if (node == null) { return(false); } //null 校验是否存在 if (String.IsNullOrEmpty(xpathparm.CheckStr)) { return(true); } //非null校验值 else { String value = String.Empty; //没有属性值直接取innertext if (!String.IsNullOrEmpty(xpathparm.Attr)) { value = node.InnerText; } else { value = node.Attributes[xpathparm.Attr]?.Value; } return(value.Equals(xpathparm.CheckStr, xpathparm.caseoption)); } }
public bool Check(string Txt, string Reg, T parm) { if (!String.IsNullOrEmpty(Txt)) { RegexPam regexPam = BaseParm.ConvertParm <RegexPam>(parm); Regex reg = new Regex(Reg, regexPam.Options); return(reg.IsMatch(Txt)); } return(false); }
public String GetResult(string Txt, string Regstr, T parm) { String retStr = String.Empty; if (!String.IsNullOrEmpty(Txt)) { RegexPam regexPam = BaseParm.ConvertParm <RegexPam>(parm); Regex reg = new Regex(Regstr, regexPam.Options); var match = reg.Match(Txt); if (match?.Groups?.Count >= regexPam.Group) { retStr = reg.Match(Txt).Groups[regexPam.Group].Value; } } return(retStr); }
public string GetResult(string Txt, string Jpath, T parm) { Txt = Txt?.Trim(); JToken token = default; if (Txt.StartsWith("{") && Txt.EndsWith("}")) { token = JsonConvert.DeserializeObject(Txt) as JObject; } else if (Txt.StartsWith("[") && Txt.EndsWith("]")) { token = JsonConvert.DeserializeObject(Txt) as JArray; } if (token != null) { JsonParm jsonam = BaseParm.ConvertParm <JsonParm>(parm); String str = Convert.ToString(token.SelectToken(Jpath)); return(str); } return(String.Empty); }
public bool Check(string Txt, string Jpath, T parm = null) { Txt = Txt?.Trim(); JToken token = default; if (Txt.StartsWith("{") && Txt.EndsWith("}")) { token = JsonConvert.DeserializeObject(Txt) as JObject; } else if (Txt.StartsWith("[") && Txt.EndsWith("]")) { token = JsonConvert.DeserializeObject(Txt) as JArray; } if (token != null) { JsonParm jsonam = BaseParm.ConvertParm <JsonParm>(parm); String str = Convert.ToString(token.SelectToken(Jpath)); return(str.Equals(jsonam.CheckStr, jsonam.caseoption)); } return(false); }
public List <String> GetResults(string Txt, string Regstr, T parm) { List <String> list = new List <String>(); if (!String.IsNullOrEmpty(Txt)) { RegexPam regexPam = BaseParm.ConvertParm <RegexPam>(parm); if (!String.IsNullOrEmpty(Regstr)) { Regex reg = new Regex(Regstr, regexPam.Options); var matches = reg.Matches(Txt); foreach (Match match in matches) { if (match?.Groups?.Count >= regexPam.Group) { list.Add(match.Groups[regexPam.Group].Value); } } } } return(list); }