倒霉的大熊

座右铭:天时地利人和

导航

php 爬虫简单示例

<?php
error_reporting(E_ALL^E_NOTICE^E_WARNING);
$url = "http://cp.360.cn/ssccq/?menu&r_a=nAFbuq";
//$url = "http://kl10.icaile.com/";
  $html = file_get_contents($url);
  //如果出现中文乱码使用下面代码
  $getcontent = iconv("gbk","utf-8", $html);  //html文档
  //echo "<textarea style='width:800px;height:600px;'>".$html."</textarea>";  
//<em class="red" id="open_issue">0126058</em>
//<ul id="open_code_list"><li class="ico-ball3">9</li> <li class="ico-ball3">8</li> <li class="ico-ball3">5</li> <li class="ico-ball3">8</li> <li class="ico-ball3">6</li> </ul>

preg_match('/<ul id="open_code_list">(.*?)<\/ul>/i', $html, $name); //定位开奖结果
preg_match('/<em class="red" id="open_issue">(.*?)<\/em>/i', $html, $num); //获取期数
//echo $name[0];

$str=$name[0];  //已定位开奖结果

/*
$str = '
<ul><li><a href="#">内容111</a></li><li><a href="#">内容111</a></li><li><a href="#">内容111</a></li><li><a href="#">内容111</a></li></ul>
';
*/
$search = '/<li class="ico-ball3">(.*?)<\/li>/is';  //提取开奖结果
preg_match_all($search,$str,$r,PREG_SET_ORDER );
//print_r($r[0]);



if($r){
echo "360时时彩开奖:<br>";
echo "第".$num[0]."期<br>";

foreach($r as $a=>$b){
    echo $b[1].'&nbsp;';
}
}else{
    echo "正在开奖,过一会刷新即可显示";
}

 

posted on 2018-01-26 15:50  倒霉的大熊  阅读(421)  评论(0编辑  收藏  举报