1 <?php 2 3 function getrealurl($url){ 4 $header = get_headers($url,1); 5 if (strpos($header[0],'301') || strpos($header[0],'302')) { 6 if(is_array($header['Location'])) { 7 return $header['Location'][count($header['Location'])-1]; 8 }else{ 9 return $header['Location']; 10 } 11 }else { 12 return $url; 13 } 14 } 15 16 17 $site=''; 18 $searchEngine='http://www.baidu.com/s?wd=site:'; 19 20 21 require('phpQuery/phpQuery.php'); 22 //实例化phpQuery 23 for($i=0;$i<50;$i++){ 24 $num=$i*10; 25 phpQuery::newDocumentFile($searchEngine.$site."&pn=".$num); 26 $index = pq("#content_left .result h3 a"); 27 foreach($index as $value){ 28 $arr=[]; 29 $arr["url"]=getrealurl(pq($value)->attr('href')); 30 $arr["title"]=pq($value)->html(); 31 $url[]=$arr; 32 } 33 } 34 35 //pn 36 file_put_contents("1.log",var_export($url,true)); 37 echo "<pre>"; 38 var_dump($url); 39 echo "</pre"; 40 41 ?>
下载地址:https://download.csdn.net/download/zhoudameinv/11120187