curl采集完整实例仅供参考(完整版)
(.*?)/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>/si'; preg_match_all($cat_rule,$fenlei[1][$i],$cats); if(!empty($cats)){ // echo "
"; // 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 ='/(.*?)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].'
'; }else{ // echo $name_r.'--'.$url_r.'
'; echo $name_r.'
'; } } } } } // 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; }本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。0/500Share your thoughts respectfully.