龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

采集彩票双色球数据与简单统计

时间:2014-07-22 14:51来源: 作者: 点击:
分享到:
采集彩票双色球数据与简单统计br / span采集/span span彩票/span span双色球/span数据,以及span分析/span span彩票/span span双色球/span数据,span采集/span与span统计/span实例br / br / 详情:a target=_blan
采集彩票双色球数据与简单统计
采集 彩票 双色球数据,以及 分析 彩票 双色球数据, 采集统计实例

详情: 采集彩票双色球数据与简单统计_PHP_WO就爱_WO就爱我的博客
由于上传文件时,只能上传utf-8编码的文件(不然中文乱码),可以会在试用时有乱码

<?php
/*
*  采集开彩票双色球数据,以及分析彩票双色球数据--采集与统计实例
*/
ini_set('display_errors', 0);//是否显示PHP错误信息,1显,0不显	
require('caipiao.php');
$Ss = new getSseqiu();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> 采集与统计 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>	

<input type="button" value="采集" onclick="document.location.href='?action=caiji'" />
<form method="get" action="?">
	期数<input type="text" name="qishu" value="<?=$qishu?>"/>
	期差<select name="cha">
		<option value="5" <?=$chas5?>>5</option>
		<option value="10" <?=$chas10?>>10</option>
		<option value="15" <?=$chas15?>>15</option>
		<option value="20" <?=$chas20?>>20</option>
	</select>
	<input type="submit" value="确定"/>
</form>
<?php
if(isset($_GET['action']) && $_GET['action'] == 'caiji'){
	// 采集数据
	$start = 1;	//开始页
	$end = 43;	//结束页
	if($Ss->main($start, $end)){
		echo '采集完成'; 	
	}	
}else{
	
	$qishu = isset($_GET['qishu']) ? intval($_GET['qishu']) : 0;
	$cha =isset($_GET['cha']) ? intval($_GET['cha']) : 0;

	$chas = 'chas'.$cha;
	$$chas = 'selected="selected"';	

	if($_GET){
		$_list = $Ss->detachNum();
		$list = array();
		$n = $i = $qishu;
		$num_arr = array();
		for( $i; $i <= $qishu+$cha; $i++ ){
			$num_arr[] = $i;
		}
		for( $n; $n >= $qishu-$cha; $n-- ){
			if(!in_array($n, $num_arr))
				$num_arr[] = $n;
		}
		sort($num_arr);
		$list = array();
		foreach($num_arr as $key => $val){
			$list[] = $_list[$val];
		}
		$dispose = $Ss->dataDispose( $list, $qishu);
		$red = $dispose['red'];
		$blue = $dispose['blue'];
?>
<table width="20%" style="float:left; text-align:center;">
	<tr>
		<td width="80px" height="25px">期数</td>
		<td width="180px">红</td>
		<td width="50px">蓝</td>
	</tr>
<?php
	foreach($list as $key => $val){
	$style = '';
	if($val[0]==$qishu){
		$style="style='background: #EBE6A9;'";	
	}
?>
	<tr <?=$style?>>
		<td height="25px"><?=$val[0]?></td>
		<td><?=$val[1]?></td>
		<td><?=$val[2]?></td>
	</tr>
<?php
	}
?>
</table>
<table width="20%" style="float:right;text-align:center;">
	<tr>
		<td width="30px" height="25px">红</td>
		<td width="30px">次数</td>
		<td width="30px">权值</td>
		<td width="30px">均值</td>
	</tr>
<?php
for($i=1;$i<=33 ;$i++ ){
?>
	<tr>
		<td height="25px"><?=$i?></td>
		<td class="hits"><?=$red[$i]['hits']?></td>
		<td class="weight"><?=$red[$i]['weight']?></td>
		<td class="mean"><?=$red[$i]['mean']?></td>
	</tr>
<?php
}
?>
</table> 
<table width="20%" style="float:right; text-align:center;">
	<tr>
		<td width="30px" height="25px">蓝</td>
		<td width="30px"><a href="javascript:void(0);" onclick="orderBy('blue_son','hits')">次数</a></td>
		<td width="30px">权值</td>
		<td width="30px">均值</td>
	</tr>
<?php
for($i=1;$i<=16 ;$i++ ){
?>
	<tr class="blue_son">
		<td><?=$i?></td>
		<td class="hits"><?=$blue[$i]['hits']?></td>
		<td class="weight"><?=$blue[$i]['weight']?></td>
		<td class="mean"><?=$blue[$i]['mean']?></td>
	</tr>
<?php
}
?>
</table>
<script language="javascript">
<!--
	function orderBy(son,ob){
		var obj_son = $('.'+son);
		var obj_ob = $('.'+ob);
		obj.each(function (){
			$(this).next('.'+ob).html();	
		});
	}
//-->
</script>
<?php

	}
?>
<?php
}
?>	
</body>
</html>

2. [文件] 采集开彩票双色球数据,以及分析彩票双色球数据--采集与统计实例 ~ 4KB     下载(84)     跳至 [1] [2] [全屏预览]

<?php
/*
* 采集开彩票双色球数据,以及分析彩票双色球数据
*/
header("Content-type: text/html; charset=utf-8");
class getSseqiu {
	var $purl= 'http://www.gdfc.org.cn/datas/history/twocolorball/history_*.html';
	var $files = 'caipiao.txt';
	var $_list ;
	function main($start,$end){
		$this->_list = $this->getFile();
		for( $i=$start; $i<=$end; $i++ ){
			$url = str_ireplace('*',$i,$this->purl);
			$this->getContent($url);
		}
		return true;
	}
	function getContent($url){
		$ch = curl_init(); 
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$data = curl_exec($ch);
		if(!$data){
			return '';	
		} 
		# 切割整个页面
		$content = explode('<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#d3d3d3">',$data);
		$content = explode('</table>',$content[1]);

		# 匹配数据
		preg_match_all("/<tr>(.*?)<\/tr>/is", $content[0] ,$out);

		unset($out[1][0]);
		$con_all = $out[1];
		$qishu = null;
		ob_start();
		foreach($con_all as $key => $val){
			preg_match("/<td align=\"center\" bgcolor=\"(#FFFFFF|#faf8e9)\">(.*?)<\/td>/", $val,$matches_1);
			$title = $matches_1[2];
			preg_match("/<td align=\"center\" bgcolor=\"(#FFFFFF|#faf8e9)\" class=\"td-luckyno\" luckyNo=\"(.*?)\"><\/td>/", $val,$matches_2);
			$value = $matches_2[2];
			$str = trim($title.':'.$value);	
			if(!in_array($str,$this->_list)){	  
				echo "\n".$str; 
			}
		}
		$ob_content = ob_get_contents();
		ob_end_clean();
		$this->saveFile($ob_content);
		
	}
	#保存文件
	function saveFile($data){
		if(!is_file($this->files)){
			$fp = fopen($this->files,'w+');		
		}else{
			$fp = fopen($this->files,'a+');
		}
		fwrite($fp, $data);
		fclose($fp);
	}
	#取文件 为数组
	function getFile(){
		$arr = array();
		if(!is_file($this->files)){
			return $arr;	
		}
		$fp = fopen($this->files,'r');
		while (!feof($fp)) {
			$arr[] = trim(fgets($fp));
		}
		fclose($fp);
		return $arr;
	}
	function detachNum(){
		$file_list = $this->getFile();
		array_shift($file_list);
		$reu = array();
		foreach($file_list as $key => $val){
			$temp = $this->getLayout($val);
			$reu[$temp[0]] = $temp;
		}
		return $reu;
	}
	function getLayout($data){
		$reu = array();
		$reu = explode(':',$data);
		$reu[2] = substr($reu[1], -2, 2);	
		$reu[1] = substr($reu[1],0,strlen($reu[1])-2);
		return $reu;
	}
	# 数据处理
	function dataDispose($data,$qishu){
		if(!is_array($data)) return false;
		$coun = count($data);
		$foolr = floor($coun/2);
		$foolr_qishu = $foolr+1;
		$red = array();
		$blue = array();
		$num = 1;
		foreach($data as $key => $val){
			if($val[0] == $qishu){	 
				$num = $foolr;
				$weight_num = $foolr_qishu;
			}elseif($val[0]<$qishu){	
				$weight_num = $num ++;	
			}elseif($val[0]>$qishu){	
				$weight_num = $num --;	
			}  
			# 红
			$son_arr = $this->stringNumber($val[1]);
			foreach($son_arr as $k2 => $v2){ 
				$red[intval($v2)]['hits'] = $red[intval($v2)]['hits']+1; 
				$red[intval($v2)]['weight'] = $red[intval($v2)]['weight']+$weight_num; 
			} 
			# 蓝
			$blue[intval($val[2])]['hits'] = $blue[intval($val[2])]['hits']+1; 
			$blue[intval($val[2])]['weight'] = $blue[intval($val[2])]['weight']+$weight_num; 
		}
		
		for( $i=0; $i<=33 ;$i++ ){
			if($red[$i]){
				$red[$i]['mean'] = round($red[$i]['hits']/$red[$i]['weight'],2) ;
			}
			
		}
		for( $i=0; $i<=16 ;$i++ ){
			
			if($blue[$i]){
				$blue[$i]['mean'] = round($blue[$i]['hits']/$blue[$i]['weight'],2);
			}
		}
		return array( 'red'=>$red, 'blue'=>$blue);
	}
	function stringNumber($string){
		$list = array();
		$list[] = substr($string, 0, 2);	
		$list[] = substr($string, 2, 2);	
		$list[] = substr($string, 4, 2);	
		$list[] = substr($string, 6, 2);	
		$list[] = substr($string, 8, 2);	
		$list[] = substr($string, 10, 2);

		return $list;
	}
//	function dbMysql(){
//		$conn = mysql_connect('localhost','root','root') or die('连接Mysql错误:'.mysql_error());
//		mysql_select_db('caipiao',$conn) or die('连接数据库错误:'.mysql_error());
//		mysql_query('set names gbk');
//	}
}
// 采集数据
//$start = 1;
//$end = 1;
//$Ss = new getSseqiu();
//$Ss->main($start, $end);
?>
精彩图集

赞助商链接