private void Init_lottery_result_list(List <Lottery_result> lr_list) { Lottery_resultTableAdapter adpter = new Lottery_resultTableAdapter(); Lottery.Lottery_resultDataTable table = adpter.GetData(); foreach (Lottery.Lottery_resultRow row in table.Rows) { Lottery_result lr = new Lottery_result() { Date = row.Date, Id = row.Id, Red_nums = new int[] { row.Red_nums01, row.Red_nums02, row.Red_nums03, row.Red_nums04, row.Red_nums05, row.Red_nums06 }, Blue_num = row.Blue_num }; lr_list.Add(lr); } }
private List <Lottery_result> Get_all_results() { string history_data_url = "http://kaijiang.zhcw.com/zhcw/html/ssq/list_{0}.html"; WebClient wc = new WebClient(); string page_html = wc.DownloadString(string.Format(history_data_url, 1)); int page_count = int.Parse(Regex.Match(page_html, @"class=""pg"".+?(?<num>\d+)").Groups["num"].Value); List <Lottery_result> lr_list = new List <Lottery_result>(); for (int i = 1; i <= page_count; i++) { Console.WriteLine("Parsing page : " + i); page_html = wc.DownloadString(string.Format(history_data_url, i)); MatchCollection mc = Regex.Matches(page_html, @"<td align=""center"">\d[\s\S]+?</em></td>"); foreach (Match m in mc) { Lottery_result lr = new Lottery_result(); MatchCollection mc_d = Regex.Matches(m.Groups[0].Value, @"<td align=""center"">(?<d>.+?)</td>"); lr.Date = DateTime.Parse(mc_d[0].Groups["d"].Value); lr.Id = int.Parse(mc_d[1].Groups["d"].Value); MatchCollection mc_n = Regex.Matches(m.Groups[0].Value, @"<em.*>(?<n>\d+)</em>"); int n; for (n = 0; n < 6; n++) { lr.Red_nums[n] = int.Parse(mc_n[n].Groups["n"].Value); } lr.Blue_num = int.Parse(mc_n[n].Groups["n"].Value); lr_list.Add(lr); } } return(lr_list); }