1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| <?php header(“Content-type: text/html; charset=utf-8”); include(‘mysql.php’); for($_GET[‘page’] = 1; $_GET[‘page’] <=5; $_GET[‘page’]++){ if(!emptyempty($_GET[‘page’])){ /**************************************** *配置开奖查询的链接地址以及通过file_get_contents()函数获取网页数据 ****************************************/ $url = “http://www.bwlc.net/bulletin/keno.html?page=”.$_GET[‘page’]; $contents = file_get_contents($url); /**************************************** *获取数据的正则表达式,其中 * $preg1:开奖期号 * $preg2:开奖号码 * $preg3:快乐飞盘 * $preg4:开奖时间 ****************************************/ $preg1 = ‘#<td>([\d]{6})</td>#i’; $preg2 = ‘#<td>([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*),([\w]*)</td>#i’; $preg3 = ‘#<td>([\d]{2})</td>#i’; $preg4 = ‘#<td>([\d]{4})-([\d]{2})-([\d]{2}) ([\d]{2}):([\d]{2})</td>#i’; /**************************************** *通过正则表达式获取符合要求的数据 ****************************************/ preg_match_all($preg1, $contents, $matches1); preg_match_all($preg2, $contents, $matches2); preg_match_all($preg3, $contents, $matches3); preg_match_all($preg4, $contents, $matches4); /**************************************** *开始使用for循环依次录入信息入数据库 ****************************************/ $o = sizeof($matches1[1]); for($i = 0; $i < $o; $i++){ /**************************************** *获取快8数据并录入数据库 ****************************************/ $qihao = $matches1[1][$i]; $sql = “select qihao from kuai8 where `qihao` = “.$qihao; $result = mysql_query($sql); $exist = mysql_fetch_row($result); if(!$exist){ $feipan = $matches3[1][$i]; for($j = 1; $j <= 20; $j++){ $num[$j] = $matches2[$j][$i]; } $kuai8 = implode(“,”,$num); $time = $matches4[1][$i].’-‘.$matches4[2][$i].’-‘.$matches4[3][$i].’ ‘.$matches4[4][$i].’:’.$matches4[5][$i]; /**************************************** *计算幸运28结果并录入 ****************************************/ for($x = 1; $x <= 19; $x++){ for($y = $x + 1; $y <= 20; $y++){ if($num[$x] > $num[$y]){ $temp = $num[$y]; $num[$y] = $num[$x]; $num[$x] = $temp; } } } $haoma1 = ($num[1] + $num[2] + $num[3] + $num[4] + $num[5] + $num[6]) % 10; $haoma2 = ($num[7] + $num[8] + $num[9] + $num[10] + $num[11] + $num[12]) % 10; $haoma3 = ($num[13] + $num[14] + $num[15] + $num[16] + $num[17] + $num[18]) % 10; $haoma = $haoma1 + $haoma2 + $haoma3; $lucky28 = implode(“,”,$num); if($haoma % 2){ $issingle = ‘单’; }else{ $issingle = ‘双’; } if($haoma < 10 || $haoma >17){ $ismiddle = ‘边’; }else{ $ismiddle = ‘中’; } if($haoma < 14){ $isbig = ‘小’; }else{ $isbig = ‘大’; } $weishu = $haoma % 10; if($weishu < 5){ $ws_isbig = ‘小’; }else{ $ws_isbig = ‘大’; } $chu3yu = $haoma % 3; $chu4yu = $haoma % 4; $chu5yu = $haoma % 5; /**************************************** *开始录入信息到两个数据表中 ****************************************/ $sql_kuai8 = “insert into kuai8(qihao, shijian, haoma, feipan) values (‘$qihao’, ‘$time’, ‘$kuai8’, ‘$feipan’)”; $insert_kuai8 = mysql_query($sql_kuai8); $sql_lucky28 = “insert into pceggs_lucky28(qihao, shijian, haoma1, haoma2, haoma3, haoma, issingle, ismiddle, isbig, weishu, ws_isbig, chu3yu, chu4yu, chu5yu, kuai8) values (‘$qihao’, ‘$time’, ‘$haoma1’, ‘$haoma2’, ‘$haoma3’, ‘$haoma’, ‘$issingle’, ‘$ismiddle’, ‘$isbig’, ‘$weishu’, ‘$ws_isbig’, ‘$chu3yu’, ‘$chu4yu’, ‘$chu5yu’, ‘$lucky28’)”; $insert_lucky28 = mysql_query($sql_lucky28); /* if(!$insert_kuai8){ echo ‘第’.$qihao.’期的kuai8表插入失败!<br />’; }else{ echo ‘第’.$qihao.’期的kuai8表插入成功!<br />’; } if(!$insert_lucky28){ echo ‘第’.$qihao.’期的lucky28表插入失败!<br />’; }else{ echo ‘第’.$qihao.’期的lucky28表插入成功!<br />’; } */ }else{ echo ‘期号为’.$qihao.’开奖号码已存在!<br />’; } } }else{ echo ‘$_GET为空!<br />’; } echo ‘<br />’; echo ‘第’.$_GET[‘page’].’页采集完成!’; echo ‘<br />’; } echo “<br />”; echo “******************<br />”; echo “* 本次采集完成! *<br />”; echo “******************<br />”; ?>
|