2017-01-27 4 views
-1

Beim Versuch, CURL zu Myntra, gibt es einen Fehler. Ich versuche Extrakt Details von DomDocument zu bekommen, aber es wird den gleichen Fehler geben:Curl-Fehler: Maximale (20) Umleitungen folgten

Maximum (20) redirects followed

Hier ist mein Code:

<?php 
     $url = 'http://www.myntra.com/sports-shoes/nike/nike-men-black-dart-12-msl-running-shoes/1547908/buy?src=search&uq=false&q=nike&p=1'; 
     $ch = curl_init($url); 
     //curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"); 
     curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
     curl_setopt($ch, CURLOPT_HEADER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_FAILONERROR, true); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: test=cookie")); 

     $cl = curl_exec($ch); 
     if(curl_exec($ch) === false) 
     { 
       echo 'Curl error: ' . curl_error($ch); 
       echo 'Curl error: ' . curl_errorno($ch); 
     }else{ 
      $dom = new DOMDocument(); 
      $xpath = new DOMXpath($dom); 
      print_r($xpath);    
     } 
?> 

Antwort

-3

Verwenden CURLOPT_MAXREDIRS Option für diese

curl_setopt($ch, CURLOPT_MAXREDIRS , 1000); 

Ich hoffe, es funktioniert, viel Glück !!

+0

Das ist selten die Heilung. Die Schleife ist das Problem und wird nicht durch Schleifen mehr Runden behoben. Oft ein Fall von Cookies. –

+0

während curl_setopt ($ ch, CURLOPT_MAXREDIRS, 1000) ;, wird es geladen, keine Ergebnisse, die ich noch habe !!! – Ashish

+0

Header entfernen ''Accept-Encoding: gzip, deflate',' –

-1
<?php 

$url = 'http://www.myntra.com/sports-shoes/nike/nike-men-black-dart-12-msl-running-shoes/1547908/buy?src=search&uq=false&q=nike&p=1'; 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:47.0) Gecko/20100101 Firefox/47.0"); 
$request_headers = [ 
       'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;', 
       'Accept-Encoding: gzip, deflate', 
       "Connection: keep-alive", 
       "Content-Type: text/html; charset=UTF-8", 

      ]; 
curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_FAILONERROR, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers); 
curl_setopt($ch, CURLOPT_ENCODING, ""); 
$cl = curl_exec($ch); 
$h = curl_getinfo($ch); 
$e = curl_error($ch); 
curl_close($ch); 
var_dump($cl); 

Manchmal müssen Sie die Request-Header senden und dann entsprechend Codierung dekodieren.

+0

Ich erhalte jetzt Antwort, aber wie man