FJ31X7Job.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using HtmlAgilityPack;
  7. using Quartz;
  8. using SCC.Common;
  9. using SCC.Crawler.Tools;
  10. using SCC.Interface;
  11. using SCC.Models;
  12. namespace SCC.Crawler.DT
  13. {
  14. /// <summary>
  15. /// 福建31选7
  16. /// </summary>
  17. [DisallowConcurrentExecution]
  18. [PersistJobDataAfterExecution]
  19. public class FJ31X7Job : IJob
  20. {
  21. /// <summary>
  22. /// 构造函数
  23. /// </summary>
  24. public FJ31X7Job()
  25. {
  26. log = new LogHelper();
  27. services = IOC.Resolve<IDTOpenCode>();
  28. email = IOC.Resolve<IEmail>();
  29. }
  30. /// <summary>
  31. /// 作业执行入口
  32. /// </summary>
  33. /// <param name="context">作业执行上下文</param>
  34. public void Execute(IJobExecutionContext context)
  35. {
  36. Config = CommonHelper.GetConfigFromDataMap(context.JobDetail.JobDataMap);
  37. //预设节假日不开奖
  38. if (Config.SkipDate.Contains(CommonHelper.SCCSysDateTime.ToString("yyyyMMdd"))) return;
  39. LatestItem = context.JobDetail.JobDataMap["LatestItem"] as OpenCode8DTModel;
  40. try
  41. {
  42. //服务启动时配置初始数据
  43. if (LatestItem == null)
  44. LatestItem = services.GetOpenCode8DTLastItem(currentLottery) ?? new OpenCode8DTModel
  45. {
  46. Term = CommonHelper.GenerateQiHaoYYQQQ(0),
  47. OpenTime = new DateTime(CommonHelper.SCCSysDateTime.Year, 1, 1)
  48. };
  49. //程序时间第二天,程序根据配置检查是否昨天有开奖
  50. isGetData = false;
  51. if (CommonHelper.CheckDTIsNeedGetData(Config))
  52. {
  53. DoMainUrl();
  54. DoBackUrl();
  55. }
  56. if (!LatestItem.Term.ToString().StartsWith(CommonHelper.SCCSysDateTime.ToString("yy")))
  57. LatestItem = new OpenCode8DTModel
  58. {
  59. Term = CommonHelper.GenerateQiHaoYYQQQ(0),
  60. OpenTime = new DateTime(CommonHelper.SCCSysDateTime.Year, 1, 1)
  61. };
  62. //当今日开奖并且当前时间是晚上8点过后开始抓取
  63. if (CommonHelper.CheckTodayIsOpenDay(Config) && CommonHelper.SCCSysDateTime.Hour > 12)
  64. {
  65. DoMainUrl();
  66. DoBackUrl();
  67. }
  68. }
  69. catch (Exception ex)
  70. {
  71. log.Error(GetType(), string.Format("【{0}】抓取时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
  72. }
  73. //保存最新期号
  74. context.JobDetail.JobDataMap["LatestItem"] = LatestItem;
  75. }
  76. /// <summary>
  77. /// 通过主站点爬取开奖数据
  78. /// (福建体彩网)
  79. /// </summary>
  80. private void DoMainUrl()
  81. {
  82. if (!string.IsNullOrEmpty(Config.MainUrl))
  83. {
  84. var OpenList = GetOpenListFromMainUrl();
  85. if (OpenList.Count == 0) return; //无抓取数据
  86. var newestQiHao = OpenList.Max(w => w.Term).ToString();
  87. var startQiNum = Convert.ToInt32(LatestItem.Term.ToString().Substring(2)) + 1;
  88. var newestQiNum = Convert.ToInt32(newestQiHao.Substring(2));
  89. if (startQiNum > newestQiNum) return; //无最新数据
  90. //处理最新开奖数据
  91. var getQiHao = string.Empty;
  92. OpenCode8DTModel matchItem = null;
  93. for (var i = startQiNum; i <= newestQiNum; i++)
  94. {
  95. getQiHao = LatestItem.Term.ToString().Substring(0, 2) + i.ToString().PadLeft(3, '0');
  96. matchItem = OpenList.Where(R => R.Term.ToString() == getQiHao).FirstOrDefault();
  97. if (matchItem != null && services.AddDTOpen8Code(currentLottery, matchItem))
  98. {
  99. //Do Success Log
  100. log.Info(GetType(), CommonHelper.GetJobMainLogInfo(Config, getQiHao));
  101. LatestItem = matchItem;
  102. isGetData = true;
  103. }
  104. }
  105. }
  106. }
  107. /// <summary>
  108. /// 获取主站开奖列表数据
  109. /// </summary>
  110. /// <returns></returns>
  111. private List<OpenCode8DTModel> GetOpenListFromMainUrl()
  112. {
  113. var result = new List<OpenCode8DTModel>();
  114. try
  115. {
  116. var htmlResource =
  117. NetHelper.GetUrlResponse(Config.MainUrl +
  118. string.Format("&r={0}", new Random().Next(1000, 9999))); //只取第一页数据,最新5条记录
  119. if (htmlResource == null) return result;
  120. var doc = new HtmlDocument();
  121. doc.LoadHtml(htmlResource);
  122. var divSections = doc.DocumentNode.SelectNodes("//div[@class='artCon KJDetail']").ToList();
  123. if (divSections == null) return result;
  124. OpenCode8DTModel model = null;
  125. var lastYear = (CommonHelper.SCCSysDateTime.Year - 1).ToString().Substring(2);
  126. HtmlNode divSummary, divDetail, table, tbody;
  127. List<HtmlNode> divContent, divInfos, spans, trs, tds, divDetails, divTexts;
  128. string term = string.Empty,
  129. detailName = string.Empty,
  130. detailNum = string.Empty,
  131. detailMoney = string.Empty;
  132. string[] openCode = null;
  133. Regex reg = null;
  134. Match m = null;
  135. foreach (var divSection in divSections)
  136. {
  137. var entity = new KaijiangDetailsEntity();
  138. entity.KaiJiangItems = new List<Kaijiangitem>();
  139. model = new OpenCode8DTModel();
  140. divInfos = divSection.ChildNodes.Where(N => N.Name.ToLower() == "div").ToList();
  141. if (divInfos.Count < 2) continue;
  142. divContent = divInfos[1].ChildNodes.Where(N => N.Name.ToLower() == "div").ToList();
  143. if (divContent.Count < 2) continue;
  144. divSummary = divContent[0]; //概述
  145. divDetail = divContent[1]; //详情
  146. spans = divSummary.ChildNodes.First(N => N.Name.ToLower() == "strong").ChildNodes
  147. .Where(N => N.Name.ToLower() == "span").ToList();
  148. term = spans[0].InnerText;
  149. if (term.StartsWith(lastYear)) break;
  150. model.Term = Convert.ToInt32(term);
  151. model.OpenTime = Convert.ToDateTime(spans[2].InnerText.Replace("年", "-").Replace("月", "-")
  152. .Replace("日", string.Empty));
  153. openCode = (spans[3].InnerText + " " + spans[4].InnerText).Trim().Split(' ');
  154. model.OpenCode1 = Convert.ToInt32(openCode[0]);
  155. model.OpenCode2 = Convert.ToInt32(openCode[1]);
  156. model.OpenCode3 = Convert.ToInt32(openCode[2]);
  157. model.OpenCode4 = Convert.ToInt32(openCode[3]);
  158. model.OpenCode5 = Convert.ToInt32(openCode[4]);
  159. model.OpenCode6 = Convert.ToInt32(openCode[5]);
  160. model.OpenCode7 = Convert.ToInt32(openCode[6]);
  161. model.OpenCode8 = Convert.ToInt32(openCode[7]);
  162. table = divDetail.ChildNodes.FirstOrDefault(N => N.Name.ToLower() == "table");
  163. if (table == null)
  164. {
  165. divDetails = divDetail.ChildNodes.Where(N => N.Name.ToLower() == "div").ToList();
  166. if (divDetails.Count < 14) continue;
  167. for (var i = 4; i < 12; i++)
  168. {
  169. divTexts = divDetails[i].ChildNodes.Where(N => N.Name.ToLower() == "#text").ToList();
  170. if (divTexts.Count < 4) continue;
  171. detailName = divTexts[0].InnerText.Replace("&nbsp;", string.Empty).Trim();
  172. detailNum = divTexts[1].InnerText.Replace("&nbsp;", string.Empty).Replace("注", string.Empty)
  173. .Trim();
  174. detailMoney = divTexts[2].InnerText.Replace("&nbsp;", string.Empty)
  175. .Replace(",", string.Empty).Replace("元", string.Empty).Trim();
  176. if (detailName == "一等奖")
  177. {
  178. var tmp = new Kaijiangitem
  179. {
  180. Name = "一等奖",
  181. Total = detailNum,
  182. TotalMoney = detailMoney
  183. };
  184. entity.KaiJiangItems.Add(tmp);
  185. }
  186. else if (detailName == "二等奖")
  187. {
  188. var tmp = new Kaijiangitem
  189. {
  190. Name = "二等奖",
  191. Total = detailNum,
  192. TotalMoney = detailMoney
  193. };
  194. entity.KaiJiangItems.Add(tmp);
  195. // Level2Num = Convert.ToInt32(detailNum);
  196. // Level2Money = Convert.ToDecimal(detailMoney);
  197. }
  198. else if (detailName == "三等奖")
  199. {
  200. var tmp = new Kaijiangitem
  201. {
  202. Name = "三等奖",
  203. Total = detailNum,
  204. TotalMoney = detailMoney
  205. };
  206. entity.KaiJiangItems.Add(tmp);
  207. }
  208. else if (detailName == "四等奖")
  209. {
  210. var tmp = new Kaijiangitem
  211. {
  212. Name = "四等奖",
  213. Total = detailNum,
  214. TotalMoney = detailMoney
  215. };
  216. entity.KaiJiangItems.Add(tmp);
  217. }
  218. else if (detailName == "五等奖")
  219. {
  220. var tmp = new Kaijiangitem
  221. {
  222. Name = "五等奖",
  223. Total = detailNum,
  224. TotalMoney = detailMoney
  225. };
  226. entity.KaiJiangItems.Add(tmp);
  227. }
  228. else if (detailName == "六等奖")
  229. {
  230. var tmp = new Kaijiangitem
  231. {
  232. Name = "六等奖",
  233. Total = detailNum,
  234. TotalMoney = detailMoney
  235. };
  236. entity.KaiJiangItems.Add(tmp);
  237. }
  238. }
  239. }
  240. else
  241. {
  242. tbody = table.ChildNodes.FirstOrDefault(N => N.Name.ToLower() == "tbody");
  243. if (tbody == null) continue;
  244. trs = tbody.ChildNodes.Where(N => N.Name.ToLower() == "tr").ToList();
  245. for (var i = 4; i < trs.Count; i++) //第一二三四行是表头
  246. {
  247. tds = trs[i].ChildNodes.Where(N => N.Name.ToLower() == "td").ToList();
  248. if (tds.Count < 3) continue;
  249. if (tds[0].InnerText.Trim() == "一等奖")
  250. {
  251. var tmp = new Kaijiangitem
  252. {
  253. Name = "一等奖",
  254. Total = tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty)
  255. .Replace(",", string.Empty).Trim(),
  256. TotalMoney =
  257. tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty)
  258. .Trim()
  259. };
  260. entity.KaiJiangItems.Add(tmp);
  261. //Level1Num = Convert.ToInt32(tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Trim());
  262. //Level1Money = Convert.ToDecimal(tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty).Trim());
  263. }
  264. else if (tds[0].InnerText.Trim() == "二等奖")
  265. {
  266. var tmp = new Kaijiangitem
  267. {
  268. Name = "二等奖",
  269. Total = tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty)
  270. .Replace(",", string.Empty).Trim(),
  271. TotalMoney =
  272. tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty)
  273. .Trim()
  274. };
  275. entity.KaiJiangItems.Add(tmp);
  276. // Level2Num = Convert.ToInt32(tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Trim());
  277. //Level2Money = Convert.ToDecimal(tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty).Trim());
  278. }
  279. else if (tds[0].InnerText.Trim() == "三等奖")
  280. {
  281. var tmp = new Kaijiangitem
  282. {
  283. Name = "三等奖",
  284. Total = tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty)
  285. .Replace(",", string.Empty).Trim(),
  286. TotalMoney =
  287. tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty)
  288. .Trim()
  289. };
  290. entity.KaiJiangItems.Add(tmp);
  291. // Level3Num = Convert.ToInt32(tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty).Replace(",", string.Empty).Trim());
  292. // Level3Money = Convert.ToDecimal(tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty).Trim());
  293. }
  294. else if (tds[0].InnerText.Trim() == "四等奖")
  295. {
  296. var tmp = new Kaijiangitem
  297. {
  298. Name = "四等奖",
  299. Total = tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty)
  300. .Replace(",", string.Empty).Trim(),
  301. TotalMoney =
  302. tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty)
  303. .Trim()
  304. };
  305. entity.KaiJiangItems.Add(tmp);
  306. }
  307. else if (tds[0].InnerText.Trim() == "五等奖")
  308. {
  309. var tmp = new Kaijiangitem
  310. {
  311. Name = "五等奖",
  312. Total = tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty)
  313. .Replace(",", string.Empty).Trim(),
  314. TotalMoney =
  315. tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty)
  316. .Trim()
  317. };
  318. entity.KaiJiangItems.Add(tmp);
  319. }
  320. else if (tds[0].InnerText.Trim() == "六等奖")
  321. {
  322. var tmp = new Kaijiangitem
  323. {
  324. Name = "六等奖",
  325. Total = tds[1].InnerText.Replace("注", string.Empty).Replace("&nbsp;", string.Empty)
  326. .Replace(",", string.Empty).Trim(),
  327. TotalMoney =
  328. tds[2].InnerText.Replace("元", string.Empty).Replace("&nbsp;", string.Empty)
  329. .Trim()
  330. };
  331. entity.KaiJiangItems.Add(tmp);
  332. }
  333. }
  334. }
  335. //抓取奖池累计数据
  336. reg = new Regex(@"([\d,.]*?)元奖金滚入下期奖池");
  337. // Sales = Convert.ToDecimal(spans[1].InnerText);
  338. entity.Trje = spans[1].InnerText;
  339. m = reg.Match(divSection.InnerHtml);
  340. if (m.Success)
  341. // Jackpot = Convert.ToDecimal(m.Result("$1"));
  342. entity.Gdje = m.Result("$1");
  343. model.Spare = entity.TryToJson();
  344. //model.Spare = string.Format("{0},{1}^一等奖|{2}|{3},二等奖|{4}|{5},三等奖|{6}|{7},四等奖|{8}|{9},五等奖|{10}|{11},六等奖|{12}|{13}",
  345. // Sales, Jackpot, Level1Num, Level1Money, Level2Num, Level2Money, Level3Num, Level3Money, Level4Num,
  346. // Level4Money, Level5Num, Level5Money, Level6Num, Level6Money);
  347. result.Add(model);
  348. }
  349. var checkDataHelper = new CheckDataHelper();
  350. var dbdata = services.GetListS<OpenCode8DTModel>(currentLottery)
  351. .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
  352. checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
  353. Config.Area, currentLottery);
  354. result = result.OrderByDescending(S => S.Term).ToList();
  355. }
  356. catch (Exception ex)
  357. {
  358. log.Error(GetType(),
  359. string.Format("【{0}】通过主站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
  360. }
  361. return result;
  362. }
  363. /// <summary>
  364. /// 通过备用站点抓取开奖数据
  365. /// (彩票两元网)
  366. /// </summary>
  367. private void DoBackUrl()
  368. {
  369. if (!string.IsNullOrEmpty(Config.BackUrl))
  370. {
  371. var OpenList = GetOpenListFromBackUrl();
  372. if (OpenList.Count == 0) return; //无抓取数据
  373. var newestQiHao = OpenList.First().Term.ToString();
  374. var startQiNum = Convert.ToInt32(LatestItem.Term.ToString().Substring(2)) + 1;
  375. var newestQiNum = Convert.ToInt32(newestQiHao.Substring(2));
  376. if (startQiNum > newestQiNum) return; //无最新数据
  377. //处理最新开奖数据
  378. var getQiHao = string.Empty;
  379. OpenCode8DTModel matchItem = null;
  380. for (var i = startQiNum; i <= newestQiNum; i++)
  381. {
  382. getQiHao = LatestItem.Term.ToString().Substring(0, 2) + i.ToString().PadLeft(3, '0');
  383. matchItem = OpenList.Where(R => R.Term.ToString() == getQiHao).FirstOrDefault();
  384. if (matchItem != null && OptimizeBackModel(ref matchItem) &&
  385. services.AddDTOpen8Code(currentLottery, matchItem))
  386. {
  387. //Do Success Log
  388. log.Info(GetType(), CommonHelper.GetJobBackLogInfo(Config, getQiHao));
  389. LatestItem = matchItem;
  390. isGetData = true;
  391. }
  392. }
  393. }
  394. }
  395. /// <summary>
  396. /// 获取备用站点开奖列表数据
  397. /// </summary>
  398. /// <returns></returns>
  399. private List<OpenCode8DTModel> GetOpenListFromBackUrl()
  400. {
  401. var result = new List<OpenCode8DTModel>();
  402. try
  403. {
  404. var url = new Uri(Config.BackUrl);
  405. var htmlResource = NetHelper.GetUrlResponse(Config.BackUrl, Encoding.GetEncoding("gb2312"));
  406. if (htmlResource == null) return result;
  407. var doc = new HtmlDocument();
  408. doc.LoadHtml(htmlResource);
  409. var table = doc.DocumentNode.SelectSingleNode("//table");
  410. if (table == null) return result;
  411. var trs = table.ChildNodes.Where(node => node.Name == "tr").ToList();
  412. OpenCode8DTModel model = null;
  413. HtmlNode nodeA = null;
  414. string optimizeUrl = string.Empty, term = string.Empty;
  415. for (var i = 2; i < trs.Count; i++) //第一二行为表头
  416. {
  417. var trstyle = trs[i].Attributes["style"];
  418. if (trstyle != null && trstyle.Value == "display:none") continue;
  419. var tds = trs[i].ChildNodes.Where(node => node.Name == "td").ToList();
  420. if (tds.Count < 10) continue;
  421. model = new OpenCode8DTModel();
  422. nodeA = tds[0].ChildNodes.Where(n => n.Name == "a").FirstOrDefault();
  423. if (nodeA == null) continue;
  424. term = nodeA.InnerText.Trim().Substring(2);
  425. if (!term.StartsWith(CommonHelper.SCCSysDateTime.ToString("yy"))) break;
  426. model.Term = Convert.ToInt64(term);
  427. optimizeUrl = nodeA.Attributes["href"].Value;
  428. model.DetailUrl = new Uri(url, optimizeUrl).AbsoluteUri;
  429. model.OpenTime = Convert.ToDateTime(tds[9].InnerText);
  430. if (tds[1].ChildNodes.Count == 0) continue;
  431. var opencodeNode = tds[1].ChildNodes.Where(n => n.Name.ToLower() == "i").ToList();
  432. if (opencodeNode.Count < 8) continue;
  433. model.OpenCode1 = Convert.ToInt32(opencodeNode[0].InnerText.Trim());
  434. model.OpenCode2 = Convert.ToInt32(opencodeNode[1].InnerText.Trim());
  435. model.OpenCode3 = Convert.ToInt32(opencodeNode[2].InnerText.Trim());
  436. model.OpenCode4 = Convert.ToInt32(opencodeNode[3].InnerText.Trim());
  437. model.OpenCode5 = Convert.ToInt32(opencodeNode[4].InnerText.Trim());
  438. model.OpenCode6 = Convert.ToInt32(opencodeNode[5].InnerText.Trim());
  439. model.OpenCode7 = Convert.ToInt32(opencodeNode[6].InnerText.Trim());
  440. model.OpenCode8 = Convert.ToInt32(opencodeNode[7].InnerText.Trim());
  441. result.Add(model);
  442. }
  443. var checkDataHelper = new CheckDataHelper();
  444. var dbdata = services.GetListS<OpenCode8DTModel>(currentLottery)
  445. .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
  446. checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
  447. Config.Area, currentLottery);
  448. result = result.OrderByDescending(S => S.Term).ToList();
  449. }
  450. catch (Exception ex)
  451. {
  452. log.Error(GetType(),
  453. string.Format("【{0}】通过备用站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
  454. }
  455. return result;
  456. }
  457. /// <summary>
  458. /// 完善备用站点福建31选7开奖实体信息
  459. /// </summary>
  460. /// <param name="model"></param>
  461. private bool OptimizeBackModel(ref OpenCode8DTModel model)
  462. {
  463. try
  464. {
  465. var htmlResource = NetHelper.GetUrlResponse(model.DetailUrl, Encoding.GetEncoding("gb2312"));
  466. if (string.IsNullOrWhiteSpace(htmlResource)) return false;
  467. var doc = new HtmlDocument();
  468. doc.LoadHtml(htmlResource);
  469. var table = doc.DocumentNode.SelectSingleNode("//table");
  470. if (table == null) return false;
  471. var trs = table.ChildNodes.Where(N => N.Name.ToLower() == "tr").ToList();
  472. List<HtmlNode> tds = null;
  473. var entity = new KaijiangDetailsEntity();
  474. entity.KaiJiangItems = new List<Kaijiangitem>();
  475. for (var i = 1; i < trs.Count; i++) //第一行为表头
  476. {
  477. tds = trs[i].ChildNodes.Where(N => N.Name.ToLower() == "td").ToList();
  478. if (tds.Count < 5) continue;
  479. if (tds[1].InnerText == "一等奖")
  480. {
  481. var tmp = new Kaijiangitem
  482. {
  483. Name = "一等奖",
  484. Total = tds[2].InnerText.Replace("注", string.Empty),
  485. TotalMoney = tds[3].InnerText
  486. };
  487. entity.KaiJiangItems.Add(tmp);
  488. // Level1Num = Convert.ToInt32(tds[2].InnerText.Replace("注", string.Empty));
  489. // Level1Money = Convert.ToDecimal(tds[3].InnerText);
  490. }
  491. if (tds[1].InnerText == "二等奖")
  492. {
  493. var tmp = new Kaijiangitem
  494. {
  495. Name = "二等奖",
  496. Total = tds[2].InnerText.Replace("注", string.Empty),
  497. TotalMoney = tds[3].InnerText
  498. };
  499. entity.KaiJiangItems.Add(tmp);
  500. }
  501. if (tds[1].InnerText == "三等奖")
  502. {
  503. var tmp = new Kaijiangitem
  504. {
  505. Name = "三等奖",
  506. Total = tds[2].InnerText.Replace("注", string.Empty),
  507. TotalMoney = tds[3].InnerText
  508. };
  509. entity.KaiJiangItems.Add(tmp);
  510. }
  511. if (tds[1].InnerText == "四等奖")
  512. {
  513. var tmp = new Kaijiangitem
  514. {
  515. Name = "四等奖",
  516. Total = tds[2].InnerText.Replace("注", string.Empty),
  517. TotalMoney = tds[3].InnerText
  518. };
  519. entity.KaiJiangItems.Add(tmp);
  520. }
  521. if (tds[1].InnerText == "五等奖")
  522. {
  523. var tmp = new Kaijiangitem
  524. {
  525. Name = "五等奖",
  526. Total = tds[2].InnerText.Replace("注", string.Empty),
  527. TotalMoney = tds[3].InnerText
  528. };
  529. entity.KaiJiangItems.Add(tmp);
  530. }
  531. if (tds[1].InnerText == "六等奖")
  532. {
  533. var tmp = new Kaijiangitem
  534. {
  535. Name = "六等奖",
  536. Total = tds[2].InnerText.Replace("注", string.Empty),
  537. TotalMoney = tds[3].InnerText
  538. };
  539. entity.KaiJiangItems.Add(tmp);
  540. }
  541. }
  542. var reg = new Regex(@"本期投注总额:([\d.,]*?)元");
  543. var match = reg.Match(htmlResource);
  544. if (match.Success) entity.Trje = match.Result("$1").Replace(",", string.Empty);
  545. reg = new Regex(@"奖池资金累计金额:([\d.,]*?)元");
  546. match = reg.Match(htmlResource);
  547. if (match.Success) entity.Gdje = match.Result("$1").Replace(",", string.Empty);
  548. model.Spare = model.TryToJson();
  549. //model.Spare = string.Format("{0},{1}^一等奖|{2}|{3},二等奖|{4}|{5},三等奖|{6}|{7},四等奖|{8}|{9},五等奖|{10}|{11},六等奖|{12}|{13}",
  550. // Sales, Jackpot, Level1Num, Level1Money, Level2Num, Level2Money, Level3Num, Level3Money, Level4Num,
  551. // Level4Money, Level5Num, Level5Money, Level6Num, Level6Money);
  552. return true;
  553. }
  554. catch (Exception ex)
  555. {
  556. log.Error(GetType(),
  557. string.Format("【{0}】通过备用站点优化开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
  558. }
  559. return false;
  560. }
  561. #region Attribute
  562. /// <summary>
  563. /// 配置信息
  564. /// </summary>
  565. private SCCConfig Config;
  566. /// <summary>
  567. /// 当天抓取的最新一期开奖记录
  568. /// </summary>
  569. private OpenCode8DTModel LatestItem;
  570. /// <summary>
  571. /// 当天抓取失败列表
  572. /// </summary>
  573. private List<string> FailedQiHaoList = null;
  574. /// <summary>
  575. /// 日志对象
  576. /// </summary>
  577. private readonly LogHelper log;
  578. /// <summary>
  579. /// 数据服务
  580. /// </summary>
  581. private readonly IDTOpenCode services;
  582. /// <summary>
  583. /// 当前彩种
  584. /// </summary>
  585. private SCCLottery currentLottery => SCCLottery.FuJian31x7;
  586. /// <summary>
  587. /// 邮件接口
  588. /// </summary>
  589. private IEmail email;
  590. /// <summary>
  591. /// 是否本次运行抓取到开奖数据
  592. /// </summary>
  593. private bool isGetData;
  594. #endregion
  595. }
  596. }