fan-bk

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 "正在开奖,过一会刷新即可显示";
}

 

分类:

技术点:

相关文章:

  • 2021-11-23
  • 2022-12-23
  • 2021-11-29
  • 2021-06-12
  • 2021-11-30
  • 2021-11-23
  • 2021-09-12
猜你喜欢
  • 2021-12-03
  • 2021-11-22
  • 2021-11-29
  • 2021-12-27
  • 2021-09-28
  • 2022-12-23
  • 2021-11-29
相关资源
相似解决方案