SourceCode/RFrameGenerate.BLL/Crowdfunding/LotteryResultManage.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using RFrameGenerate.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace RFrameGenerate.BLL
{
    public class LotteryResultManage
    {
        private const string HtmlPattern = @"<table[^>]*class\s*=\s*(?:'|"")awardList(?:'|"")[^>]*>.*?</table>";
        private const string DataPattern = @"<td[^>]*class\s*=\s*(?:'|"")start(?:'|"")[^>]*>\s*(?<period>[^>]*?)\s*</td>\s*<td[^>]*class\s*=\s*(?:'|"")award-winNum(?:'|"")[^>]*>\s*(?<number>[^>]*?)\s*</td>";
        /// <summary>
        /// 采集开奖结果
        /// </summary>
        public static Result CollectLotteryResult(string url = null)
        {
            HttpWebResponse response = null;
            if (string.IsNullOrEmpty(url) == true)
                url = string.Format("http://caipiao.163.com/award/cqssc/{0}.html", DateTime.Now.ToString("yyyyMMdd"));
            try
            {
                int tryCount = 0;
                string html = string.Empty;
                while (tryCount++ < 3)
                {
                    response = RequestHepler.CreateGetHttpResponse(url);


                    if (response.Headers.AllKeys.Contains<string>("Content-Encoding") && (response.Headers.Get("Content-Encoding").ToLower().Trim() == "gzip"))
                    {
                        using (var reader = new StreamReader(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress, true), System.Text.Encoding.UTF8))
                        {
                            html = reader.ReadToEnd();
                        }
                    }
                    else
                    {
                        using (var reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                        {
                            html = reader.ReadToEnd();
                        }
                    }


                    if (!string.IsNullOrEmpty(html) && Regex.IsMatch(html, HtmlPattern, RegexOptions.Singleline | RegexOptions.IgnoreCase)) break;
                }

                if (string.IsNullOrEmpty(html) || !Regex.IsMatch(html, DataPattern)) return new Result(false, "采集结果为空!");

                string strNumber = string.Empty;
                string strPeriod = string.Empty;
                int maxPeriod = 0;
                int tempPeriod = 0;
                foreach (Match match in Regex.Matches(html, DataPattern, RegexOptions.Singleline | RegexOptions.IgnoreCase))
                {
后面还有 67 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。