<?php $img =array( ‘jpg‘, ‘png‘, ‘gif‘, ‘bmp‘, ‘psd‘, ‘tif‘, ‘jpeg‘, ); //$url = ‘http://www.3lian.com/down/pic/index_(2,5).html‘; $url = ‘http://image.baidu.com/i?tn=baiduimage&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1348625333024_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&word=%BA%E1%B7%F9‘; $prel = ‘/\([0-9]+,[0-9]+\)/i‘; $myurl; if(preg_match($prel,$url,$arr)){ $temp = substr($arr[0],1,strlen($arr[0])-2); $mymunber = explode(‘,‘,$temp); $temparr = explode($arr[0],$url); for($i=$mymunber[0];$i<=$mymunber[1];$i++){ $myurl[] = $temparr[0].$i.$temparr[1]; } }else{ $myurl = $url; } /* echo "<pre>"; print_r($myurl); echo "</pre>"; */ $prel = ‘/(?:http?|https?):\/\/(?:[^\.\/\(\)\?]+)\.(?:[^\.\/]+)\.(?:com|cn|net|org)\/(?:[^\.:\"\‘\(\)\?]+)\.(jpg|png|gif)/i‘; if(is_array($myurl)){ $arr = array(); $imgkey = array(); foreach($myurl as $value){ $code = file_get_contents($value); preg_match_all($prel,$code,$arrimg); $arr = array_merge($arr,$arrimg[0]); $imgkey = array_merge($imgkey,$arrimg[1]); } set_time_limit(0); if(!empty($arr)){ echo ‘<pre>‘; print_r($arr); echo ‘</pre>‘; foreach($arr as $key=>$value){ list($w,$h,$t,$a) = getimagesize($value); if($w<930 || $h<200){ continue; } ob_start(); readfile($value); $obj = ob_get_contents(); ob_end_clean(); $dir = ‘F:/php/‘; if(!is_dir($dir)){ mkdir($dir,0777); } $filename = $dir.date(‘Ymd‘).rand(10000,99999).‘.‘.$imgkey[$key]; $file = file_get_contents($value); $fo = @fopen($filename,‘a‘); $fw = fwrite($fo,$obj); if(in_array($imgkey[$key],$img)){ echo ‘<img src="‘.$value.‘" />‘; } } } }else{ $code = file_get_contents($url); set_time_limit(0); if(preg_match_all($prel,$code,$arrimg)){ echo ‘<pre>‘; print_r($arrimg); echo ‘</pre>‘; foreach($arrimg[0] as $key=>$value){ list($w,$h,$t,$a) = @getimagesize($value); if($w<300 || $h<200){ continue; } ob_start(); readfile($value); $obj = ob_get_contents(); ob_end_clean(); $dir = ‘F:/php/‘; if(!is_dir($dir)){ mkdir($dir,0777); } $filename = $dir.date(‘Ymd‘).rand(10000,99999).‘.‘.$arrimg[1][$key]; $file = file_get_contents($value); $fo = @fopen($filename,‘a‘); $fw = fwrite($fo,$obj); if(in_array($arrimg[1][$key],$img)){ echo ‘<img src="‘.$value.‘" />‘; } } } } echo ‘<script>alert("采集完成!")</script>‘; ?>
时间: 2024-11-07 22:35:46