2017-06-18 26 views
0

我想抓取頁面,但因爲cookie而導致許多頁面失敗。我想我需要把頁面的cookies放進CURLOPT_COOKIE。但是我仍然沒有得到這種類型的頁面的內容。PHP用CURL抓取網頁時處理cookie

URL捲曲:http://www.roguefitness.com/reebok-crossfit-speed-teal-dust-forest-grey-black-hery-yellow-skull-grey

$cookie = array(); 
$cookie[] = "visid_incap_626072=wppfexB2Rx2G+0Fl0p5ObF3HRlkAAAAAQUIPAAAAAABkbU4BWHOCgsesm58ql+4y"; 
$cookie[] = "incap_ses_415_626072=L8pAJA2442e3l2pfKmHCBV3HRlkAAAAAK0T9IPzsPD+zRr2W8AY4kA=="; 
$cookie[] = "incap_ses_541_626072=BGgpDAFx32HueJcV/QSCB5nHRlkAAAAAysy38ULGSs0RqTsyx2QsJg=="; 
$cookie = implode('; ', $cookie); 

$cookieJar = tempnam ("/dev/null", "CURLCOOKIE"); 
$cookieFile = tempnam ("/dev/null", "CURLCOOKIE");  
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieJar); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile); 
curl_setopt($ch, CURLOPT_COOKIE, $cookie); 

的反應是不網頁內容,但這樣的:

HTTP/1.1 200 OKContent-Type: text/htmlCache-Control: no-cacheConnection: closeContent-Length: 670X-Iinfo: 8-65878311-0 0NNN RT(1497811103027 0) q(0 -1 -1 -1) r(0 -1) B12(4,316,0) 

任何幫助將真正理解!

回答

0

這裏是代碼的缺失行這使得它的工作:

curl_setopt($ch, CURLOPT_COOKIESESSION, true);