Example #1
0
        /* =======================================================       新的程序函数                  */
        /// <summary>
        /// 通用Get获取可以用于正则表达式的内容
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private static string GetResponseToApplingPatternExoression(ItemSourceModel model)
        {
            var res = HttpHelper.HttpGetX(InsteadOfUrlParameter(model.GatherUrl), out _, "utf-8");

            return(SubstringResponse(res, model.ContentBegin ?? "", model.ContentEnd ?? ""));
            //return SubstringResponse(HttpHelper.GetResponse(InsteadOfUrlParameter(model.GatherUrl)), model.ContentBegin ?? "", model.ContentEnd ?? "");
        }
Example #2
0
        /// <summary>
        /// 获取当前交易日期
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private static string GetCurrentTradingDate(ItemSourceModel model)
        {
            string response = GetResponseToApplingPatternExoression(model);

            if (response.Length > 2)
            {
                Regex rg = new Regex(model.FieldPattern, RegexOptions.IgnoreCase);//指定不区分大小写的匹配
                if (rg.IsMatch(response))
                {
                    return(rg.Match(response).Groups[1].Value);
                }
                else
                {
                    return(response);
                }
            }
            return(response);
        }
Example #3
0
        /// <summary>
        /// 根据正则获取DataTable结构
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private static string GatherAndSave(ItemSourceModel model)
        {
            string response = GetResponseToApplingPatternExoression(model);

            if (response.Length > 2)
            {
                Regex rg = new Regex(model.FieldPattern, RegexOptions.IgnoreCase);//指定不区分大小写的匹配
                if (rg.IsMatch(response))
                {
                    DataTable dataTable = DataTableHelper.CreateDataTableByPattern(model.FieldPattern, model.ExtraFieldPattern);
                    //return rg.Match(response).Groups[1].Value;
                    // 插入到后台
                    MatchCollection matches = rg.Matches(response);
                    for (int i = 0; i < matches.Count; i++)
                    {
                        Match           matchitem = matches[i];
                        GroupCollection gc        = matchitem.Groups;
                        DataRow         dr        = dataTable.NewRow();
                        //多少个匹配组就创建多少个列值
                        for (int j = 1; j < gc.Count; j++)
                        {
                            dr[j - 1] = gc[j];
                        }

                        if (!string.IsNullOrEmpty(model.ExtraFieldPattern))
                        {
                            JObject jObject = new JObject(@"{GatherDate:当前日期, GatherDateNumber 当前日期序号, GatherMinuteNumber 当前分钟序号 }");
                            foreach (var item in jObject.Properties())
                            {
                                dr[item.Name] = GetCalculateValue(item.Value.ToObject <string>());
                            }
                        }
                    }
                }
                else
                {
                    return(response);
                }
            }
            return(response);
        }