如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
<?php header('Content-type:text/html;charset=utf-8'); error_reporting(E_ERROR | E_WARNING | E_PARSE); set_time_limit(0);//d等待时间.不限制 ini_set('memory_limit','200m');//设置内存 $url = $_GET['url']; if(!isset($url)){ die("请输入地址"); } //获取网页 $str = get_str($url); // $block_rule ='//si'; s空格换行字符 i 不区分大小写 $block_rule ='/<li class="clearfix">(.*?)<p class="info">/si'; preg_match_all($block_rule,$str,$fenlei); if(!empty($fenlei)){ // print_r($fenlei[1]); $count = count($fenlei[1]); for($i=0;$i<$count;$i++){ $cat_rule='/<a href="(.*?)" target="_blank">(.*?)<\/a>/si'; preg_match_all($cat_rule,$fenlei[1][$i],$cats); if(!empty($cats)){ // echo "<pre>"; // print_r($cats[1]); // print_r($cats[2]); if(!empty($cats[1][1])){ $url_r = $cats[1][1]; $name_r = $cats[2][1]; $content_str = get_str($url_r); $content_rule ='/<div class="newfujian">(.*?)rel="nofollow" target="_blank"><\/a>.*?<\/div>.*?<\/div>/si'; // echo $content_str; @preg_match_all($content_rule,$content_str,$cont); if(!empty($cont)){ echo $name_r.$cont[1][0].'<br> <hr>'; }else{ // echo $name_r.'--<a href="'.$url_r.'" target="_blank">'.$url_r.'</a><br> '; echo $name_r.'</a><br> '; } } } } } // echo $str; //curl获取网页内容 function get_str($url){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); $str = curl_exec($ch); curl_close($ch); return $str; }