效果图
代码
<?php$url = "http://要抓取的网页";$contents = file_get_contents($url);//如果出现中文乱码使用下面代码//$getcontent = iconv("gb2312", "utf-8",$contents);//echo $contents;//exit;$mode = "#<ol class=\"linenums\">(.*)</ol>#is";preg_match_all($mode,$contents,$matches);//print_r($matches);$xinxi_str=$matches[0][0];//echo $xinxi_str;$xinxi_arr1=explode("<li ",$xinxi_str);//print_r($xinxi_arr1);foreach($xinxi_arr1 as $key=>$value){$xinxi_arr2=explode("</li>",$xinxi_arr1[$key]);$xinxi_arr1[$key]=$xinxi_arr2[0];}//print_r($xinxi_arr1);//echo count($xinxi_arr1);echo "<table border='1px' bordercolor='green' cellspacing='0px' ;";echo "<tr><th>svcname</th><th>status</th>";for($j=1;$j<count($xinxi_arr1);$j++){$mode2= "#>(.*)#is";preg_match_all($mode2,$xinxi_arr1[$j],$matches2);//print_r($matches2);$title_str=$matches2[0][0];$title_arr=explode(">",$title_str);//print_r($title_arr);$title=str_replace("</","",$title_arr[1]);if (strpos($title,".default.run")){$list_str=str_replace(".default.run="," ",$title_arr[1]);$list_arr=explode(" ",$list_str);//print_r($list_arr);echo"<tr><td>{$list_arr[0]}</td><td>{$list_arr[1]}</td>";}}echo "<h3>服务信息列表</h3>";echo "</table>";?>