| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Diagnostics;
 
- using System.Linq;
 
- using System.Text;
 
- using HtmlAgilityPack;
 
- using Quartz;
 
- using SCC.Common;
 
- using SCC.Interface;
 
- using SCC.Models;
 
- namespace SCC.Crawler.AutoCheckJob
 
- {
 
-     public class AutoCheckKJP5Job : IJob
 
-     {
 
-         public AutoCheckKJP5Job()
 
-         {
 
-             log = new LogHelper();
 
-             services = IOC.Resolve<IDTOpenCode>();
 
-             email = IOC.Resolve<IEmail>();
 
-         }
 
-         public void Execute(IJobExecutionContext context)
 
-         {
 
-             Config = CommonHelper.GetConfigFromDataMap(context.JobDetail.JobDataMap);
 
-             
 
-             
 
-             Check();
 
-         }
 
-         private void Check()
 
-         {
 
-             try
 
-             {
 
-                 var dict = services.GetLast1NTerm(currentLottery, 10);
 
-                 if (dict.Count > 0)
 
-                     foreach (var dic in dict)
 
-                     {
 
-                         var key = dic.Key;
 
-                         var Spare = dic.Value;
 
-                         var openList = GetOpenListFromMainUrl(Config.MainUrl);
 
-                         OpenCodePL5TModel matchItem = null;
 
-                         matchItem = openList.FirstOrDefault(r => r.Term.ToString() == key.ToString());
 
-                         var res = GetKaijiangDetails(key.ToString());
 
-                         
 
-                         bool isSucc = services.UpdateKJDetailP5ByTerm(currentLottery, key, res, matchItem);
 
-                         if (isSucc)
 
-                         {
 
-                             Trace.WriteLine($"更新{Config.LotteryName}第{key}期开奖详情成功!");
 
-                             log.Info(GetType(), $"更新{Config.LotteryName}第{key}期开奖详情成功!");
 
-                         }
 
-                         else
 
-                         {
 
-                             Trace.WriteLine($"更新{Config.LotteryName}第{key}期开奖详情失败!");
 
-                             log.Error(GetType(), $"更新{Config.LotteryName}第{key}期开奖详情失败!");
 
-                         }
 
-                     }
 
-             }
 
-             catch (Exception e)
 
-             {
 
-                 log.Error(GetType(), e);
 
-             }
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         private string GetKaijiangDetails(string qishu)
 
-         {
 
-             var url = "https://www.8200.cn/kjh/p5/" + qishu + ".htm";
 
-             var htmlResource = NetHelper.GetUrlResponse(url, Encoding.GetEncoding("utf-8"));
 
-             if (htmlResource == null) return null;
 
-             var doc = new HtmlDocument();
 
-             doc.LoadHtml(htmlResource);
 
-             var div = doc.DocumentNode.SelectSingleNode("//div[@class='text-16']");
 
-             if (div == null) return null;
 
-             
 
-             var jiangjin = div.ChildNodes.Where(node => node.Name == "p").ToList();
 
-             
 
-             
 
-             var table = doc.DocumentNode.SelectSingleNode("//table");
 
-             var trs = table.ChildNodes.Where(node => node.Name == "tr").ToList();
 
-             var trje = jiangjin[1].InnerText.Replace(" 万元", "").Replace("本期销量:", "").Replace("--", "0").Replace(",", "")
 
-                 .Trim();
 
-             var entity = new KaijiangDetailsEntity
 
-             {
 
-                 Gdje = null,
 
-                 Trje = trje == "0" ? "0" : (double.Parse(trje) * 10000).ToString()
 
-             };
 
-             
 
-             
 
-             var list = new List<Kaijiangitem>();
 
-             for (var i = 0; i < trs.Count; i++)
 
-             {
 
-                 var tds = trs[i].ChildNodes.Where(node => node.Name == "td").ToList();
 
-                 var kaijiangitem = new Kaijiangitem();
 
-                 var TotalMoney = tds[1].InnerText.Replace(" 万元", "").Replace("--", "0").Replace(",", "").Trim();
 
-                 kaijiangitem.Name = tds[0].InnerText.Trim();
 
-                 kaijiangitem.TotalMoney = TotalMoney == "0" ? "0" : (double.Parse(TotalMoney) * 10000).ToString();
 
-                 kaijiangitem.Total = tds[2].InnerText.Trim().Replace(" 注", "").Replace("--", "0").Trim();
 
-                 list.Add(kaijiangitem);
 
-             }
 
-             entity.KaiJiangItems = list;
 
-             return entity.TryToJson();
 
-         }
 
-         private List<OpenCodePL5TModel> GetOpenListFromMainUrl(string mainUrl)
 
-         {
 
-             var result = new List<OpenCodePL5TModel>();
 
-             try
 
-             {
 
-                 var url = new Uri(mainUrl);
 
-                 var htmlResource = NetHelper.GetUrlResponse(mainUrl, Encoding.GetEncoding("utf-8"));
 
-                 if (htmlResource == null) return result;
 
-                 var doc = new HtmlDocument();
 
-                 doc.LoadHtml(htmlResource);
 
-                 var table = doc.DocumentNode.SelectSingleNode("//table");
 
-                 if (table == null) return result;
 
-                 var trs = table.ChildNodes.Where(node => node.Name == "tr").ToList();
 
-                 OpenCodePL5TModel model = null;
 
-                 HtmlNode nodeA = null;
 
-                 var optimizeUrl = string.Empty;
 
-                 for (var i = 0; i < trs.Count; i++) 
 
-                 {
 
-                     var trstyle = trs[i].Attributes["style"];
 
-                     if (trstyle != null && trstyle.Value == "display:none") continue;
 
-                     var tds = trs[i].ChildNodes.Where(node => node.Name == "td").ToList();
 
-                     if (tds.Count < 6) continue;
 
-                     model = new OpenCodePL5TModel();
 
-                     var Term = tds[0].InnerText.Trim();
 
-                     if (Term.Length <= 7)
 
-                     {
 
-                         model.Term = Convert.ToInt64("20" + Term);
 
-                     }
 
-                     else
 
-                     {
 
-                         model.Term = Convert.ToInt64(Term);
 
-                     }
 
-                     optimizeUrl = model.Term.ToString();
 
-                     model.OpenTime = Convert.ToDateTime(tds[1].InnerText.Substring(0, 5));
 
-                     var openCodeString = tds[2].InnerText.Replace("    ", "").Trim();
 
-                     if (openCodeString == "--")
 
-                     {
 
-                         model.OpenCode1 = Convert.ToInt32("-1");
 
-                         model.OpenCode2 = Convert.ToInt32("-1");
 
-                         model.OpenCode3 = Convert.ToInt32("-1");
 
-                         model.OpenCode4 = Convert.ToInt32("-1");
 
-                         model.OpenCode5 = Convert.ToInt32("-1");
 
-                     }
 
-                     else
 
-                     {
 
-                         model.OpenCode1 = Convert.ToInt32(openCodeString.Substring(0, 1));
 
-                         model.OpenCode2 = Convert.ToInt32(openCodeString.Substring(2, 1));
 
-                         model.OpenCode3 = Convert.ToInt32(openCodeString.Substring(4, 1));
 
-                         model.OpenCode4 = Convert.ToInt32(openCodeString.Substring(6, 1));
 
-                         model.OpenCode5 = Convert.ToInt32(openCodeString.Substring(8, 1));
 
-                     }
 
-                     model.KaiJiHao = null;
 
-                     model.ShiJiHao = tds[3].InnerText.Trim().Replace(" ", ",").Trim();
 
-                     var details = GetKaijiangDetails(optimizeUrl);
 
-                     model.Spare = details;
 
-                     result.Add(model);
 
-                 }
 
-                 result = result.OrderByDescending(S => S.Term).ToList();
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 log.Error(GetType(),
 
-                     string.Format("【{0}】通过主站抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
 
-             }
 
-             return result;
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         #region Attribute
 
-         
 
-         
 
-         
 
-         private SCCConfig Config;
 
-         
 
-         
 
-         
 
-         private OpenCode7DTModel LatestItem = null;
 
-         
 
-         
 
-         
 
-         private List<string> FailedQiHaoList = null;
 
-         
 
-         
 
-         
 
-         private readonly LogHelper log;
 
-         
 
-         
 
-         
 
-         private readonly IDTOpenCode services;
 
-         
 
-         
 
-         
 
-         private SCCLottery currentLottery => SCCLottery.PL5;
 
-         
 
-         
 
-         
 
-         private IEmail email;
 
-         
 
-         
 
-         
 
-         private bool isGetData = false;
 
-         #endregion
 
-     }
 
- }
 
 
  |