Exemplo n.º 1
0
        private bool Down11X5(DownParameter param, SQLServer.D11X5.DwNumberBiz biz, DateTime currentDate)
        {
            int intDate = int.Parse(currentDate.ToString("yyyyMMdd"));
            string url = string.Format(param.Category.DownUrl, intDate, "&");

            try
            {
                string htmlText = Regex.Match(this._webClient.DownloadString(url), "<tbody id=\"row_show\">.*</tbody>",
                    RegexOptions.Singleline | RegexOptions.IgnoreCase).Value;
                MatchCollection matchs = Regex.Matches(htmlText, "<tr>.*?</tr>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (matchs.Count == 0)
                {
                    Logger.Instance.Write(string.Format("name:{0},url:{1},msg:{2}", param.Category.Name, url, "count=0"));
                    return false;
                }

                long lastP = biz.GetLatestPeroid();
                //HashSet<long> pSet = biz.GetPeroidsByDate(currentDate);
                for (int i = matchs.Count - 1; i >= 0; i--)
                {
                    Match match = matchs[i];
                    string peroid = Regex.Match(match.Value, "<td width=\"25%\">(\\d+)期</td>",
                        RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value.Trim();
                    string datetime = Regex.Match(match.Value, "<td width=\"25%\">(\\d{4}-\\d{2}-\\d{2}.*?)</td>",
                        RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value.Trim();
                    string code = Regex.Match(match.Value, @"[<spans >|<span >](\d{2},\d{2},\d{2},\d{2},\d{2})[</spans>|<spans>]",
                        RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value.Trim();

                    if (string.IsNullOrEmpty(code) || code.Trim().Length == 0) continue;

                    int p = int.Parse(peroid);
                    //把期号统一成{yyyymmddnn}
                    if (p < 2000000000) p += 2000000000;
                    //if (pSet.Contains(p)) continue;
                    if (p <= lastP) continue;

                    int n = int.Parse(peroid.Substring(peroid.Length - 2));
                    if (!biz.Add(p, n, code, intDate, datetime)) return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                Logger.Instance.Write(string.Format("name:{0},url:{1},msg:{2}", param.Category.Name, url, ex.Message));
                return false;
            }
        }
Exemplo n.º 2
0
        private bool Down3D(DownParameter param, SQLServer.D3.DwNumberBiz biz, DateTime currentDate)
        {
            string url = param.Category.DownUrl;

            try
            {
                string htmlText = Regex.Match(this._webClient.DownloadString(url), "<div id=\"conKjlist\" class=\"kjlist\">.*?</table>",
                    RegexOptions.Singleline | RegexOptions.IgnoreCase).Value;
                MatchCollection matchs = Regex.Matches(htmlText, "<tr>.*?</tr>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (matchs.Count == 0)
                {
                    Logger.Instance.Write(string.Format("name:{0},url:{1},msg:{2}", param.Category.Name, url, "count=0"));
                    return false;
                }

                long lastP = biz.GetLatestPeroid();
                //HashSet<long> pSet = biz.GetPeroidsByDate(currentDate);
                for (int i = matchs.Count - 1; i >= 0; i--)
                {
                    Match match = matchs[i];
                    string peroid = Regex.Match(match.Value, "<td>(\\d{7})</td>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value.Trim();
                    string datetime = Regex.Match(match.Value, "<td>(\\d{4}-\\d{2}-\\d{2})</td>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value.Trim();
                    string code = Regex.Match(match.Value, "<div class=\"aball\">.*?</div>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Value;
                    code = Regex.Replace(code, "<.*?>", "");
                    code = string.Join(",", code.ToArray());

                    if (string.IsNullOrEmpty(code) || code.Trim().Length == 0) continue;

                    int intDate = int.Parse(datetime.Replace("-", ""));
                    int p = int.Parse(peroid);

                    //把期号统一成{yyyynnn}
                    if (p < 2000000) p += 2000000;
                    //if (pSet.Contains(p)) continue;
                    if (p <= lastP) continue;

                    int n = int.Parse(peroid.Substring(peroid.Length - 3));
                    if (!biz.Add(p, n, code, intDate, datetime)) return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                Logger.Instance.Write(string.Format("name:{0},url:{1},msg:{2}", param.Category.Name, url, ex.Message));
                return false;
            }
        }