PHP防抓取數據curl 解決方法


1.使用Snoopy或curl傳搜索引擎爬蟲的USERAGENT值。  

  查看搜索引擎爬蟲的USERAGENT值:http://www.cnblogs.com/grimm/p/5068092.html (http://www.geekso.com/spdier-useragent/  )

2.使用Snoopy或curl傳referer值。  

   如:$snoopy->referer = 'http://www.google.com';        

     $header[] = "Referer: http://www.google.com/";

 3.使用Snoopy或curl代理。    

  如:$snoopy->proxy_host  = "59.108.44.41";          $

    snoopy->proxy_port  = "3128";  

4.使用Snoopy或curl防造IP。  

   如:$snoopy->rawheaders['X_FORWARDED_FOR'] = '127.0.0.1';        

     $snoopy->rawheaders['CLIENT-IP'] = '127.0.0.1';  

5.用php寫一個重起路由器的程序,這樣就會獲得新的ip地址。

 6.如果發現重起路由器還是顯示被封,有可能對方封了你路由器的mac地址,現在路由器都有修改MAC的功能,可以寫程序或手動修改路由器的MAC地址。

例如:

  php curl偽裝抓取

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0 ); // 過濾HTTP頭
curl_setopt($ch, CURLOPT_TIMEOUT, 40);                                                                                                                   
curl_setopt($ch, CURLOPT_USERAGENT, 'Baiduspider+(+http://www.baidu.com/search/spider.htm)');  
                                                       
$ip = '220.181.7.121';
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:' . $ip, 'CLIENT-IP:' . $ip));                                                               
curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com/search/spider.html");                                                                            
 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);// 顯示輸出結果                                                                                               
$responseText = curl_exec($ch);                                                                                                                          
curl_close($ch)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM