我正在使用curl並傳遞一個url,頁面號= 2,但它重定向到第一頁。我需要你的幫助。請幫我curl重定向到錯誤頁面?
例子:
如果我通過http://itunes.apple.com/us/genre/mobile-software-applications/id6018?mt=8&letter=A&page=2#page
它重定向到= http://itunes.apple.com/us/genre/mobile-software-applications/id6018?mt=8&letter=A&page=1#page
<?php
$agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL, "http://itunes.apple.com/us/genre/mobile-software- applications/id6018?mt=8&letter=A&page=2#page");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else{
echo $output = curl_exec($ch);
}
curl_close($ch);
?>
但它總是重定向到第一頁,我沒有得到第2頁或給定網址。
你確實意識到你正在調用exec兩次,對吧? – 2010-04-06 12:33:57