// 分析网页抓取开奖结果 func analyzeHtml(html string) ([]entity.TwoColorBall, error) { // 使用正则分析网页 regex := regexp.MustCompile(`<tr>\s*?<td align="center">([0-9,\-]*?)</td>\s*?<td align="center">([0-9]*?)</td>\s*?<td align="center" style="padding-left:10px;">\s*?<em class="rr">(\d{2})</em>\s*?<em class="rr">(\d{2})</em>\s*?<em class="rr">(\d{2})</em>\s*?<em class="rr">(\d{2})</em>\s*?<em class="rr">(\d{2})</em>\s*?<em class="rr">(\d{2})</em>\s*?<em>(\d{2})</em></td>(?s).*?</tr>`) group := regex.FindAllStringSubmatch(html, -1) // log.Println(group) // log.Println("共计:", len(group)) results := make([]entity.TwoColorBall, 0) for _, section := range group { item := entity.TwoColorBall{} item.ID = crypto.GetUniqueInt64() item.No = section[2] item.Date = section[1] item.Red1, _ = strconv.Atoi(section[3]) item.Red2, _ = strconv.Atoi(section[4]) item.Red3, _ = strconv.Atoi(section[5]) item.Red4, _ = strconv.Atoi(section[6]) item.Red5, _ = strconv.Atoi(section[7]) item.Red6, _ = strconv.Atoi(section[8]) item.Blue1, _ = strconv.Atoi(section[9]) results = append(results, item) } return results, nil }