/// <summary> /// 返回实体数据列表 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="analysisEnum">解析模式</param> /// <param name="htmlDocument">HtmlDocument</param> /// <param name="xPath">XPath 查询语句</param> /// <param name="xPathMatchList">属性 XPath 查询语句列表</param> /// <param name="propertyMatchList">属性匹配,Dictionary<string, object> 或 new {}</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static List <T> ToEntityList <T>(HtmlAnalysisEnum analysisEnum, HtmlDocument htmlDocument, string xPath, List <XPathMatch> xPathMatchList = null, object propertyMatchList = null, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { if (analysisEnum == HtmlAnalysisEnum.Strict) { return(ToEntityListStrict <T>(htmlDocument, xPath, xPathMatchList, propertyMatchList, reflectionType)); } else { return(ToEntityListNormal <T>(htmlDocument, xPath, xPathMatchList, propertyMatchList, reflectionType)); } }
/// <summary> /// 返回实体数据列表 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="analysisEnum">解析模式</param> /// <param name="htmlDocument">HtmlDocument</param> /// <param name="xPath">XPath 查询语句</param> /// <param name="xPathMatchDict">属性 XPath 查询语句字典</param> /// <param name="propertyMatchList">属性匹配,Dictionary<string, object> 或 new {}</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static List <T> ToEntityList <T>(HtmlAnalysisEnum analysisEnum, HtmlDocument htmlDocument, string xPath, Dictionary <string, string> xPathMatchDict, object propertyMatchList = null, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { List <XPathMatch> xPathMatchList = new List <XPathMatch>(); foreach (var keyValueItem in xPathMatchDict) { xPathMatchList.Add(new XPathMatch() { PropertyName = keyValueItem.Key, XPath = keyValueItem.Value }); } return(ToEntityList <T>(analysisEnum, htmlDocument, xPath, xPathMatchList, propertyMatchList, reflectionType)); }
/// <summary> /// 同步获取数据 /// </summary> /// <param name="analysisEnum">解析模式</param> /// <param name="httpItem">HttpItem</param> /// <param name="xPath">XPath 查询语句</param> /// <param name="xPathMatchList">属性 XPath 查询语句列表</param> /// <param name="propertyMatchList">属性匹配,Dictionary<string, object> 或 new {}</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public List <T> ToList <T>(HtmlAnalysisEnum analysisEnum, HttpItem httpItem, string xPath, List <XPathMatch> xPathMatchList = null, object propertyMatchList = null, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { HttpHelper httpHelper = new HttpHelper(); HttpResult httpResult = httpHelper.GetHtml(httpItem); if (httpResult == null) { return(null); } HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(httpResult.Html); return(HtmlAnalysisHelper.ToEntityList <T>(analysisEnum, htmlDocument, xPath, xPathMatchList, propertyMatchList, reflectionType)); }