2011-05-15 45 views
1

希望一切順利。無法用CURL管理會話

我需要一些幫助。

我想用CURL(http://wap.ebay.com/Pages/ViewItem.aspx?aid=160585148382)刮一個頁面,當這個頁面加載時,那個頁面中有另一個鏈接(Anchor Text :說明),我也想刮那頁。

當您直接轉到描述頁面(http://wap.ebay.com/Pages/ViewItemDesc.aspx?aid=280655395879 & emvcc = 0)放在你的瀏覽器,它會告訴你錯誤,如「Session Expired或沒有拍賣細節找到「,我認爲要刮那頁,我們需要有一些會議或someting。

所以,首先我想刮http://wap.ebay.com/Pages/ViewItem.aspx?aid=280655395879 &然後提取描述按鈕中的網址,然後前綴(http://wap.ebay.com/Pages),以便它成爲一個完整的URL,然後我想來劃分該URL的內容。

但看起來我不能保持會議活着。

我的代碼是:

<? 
require_once('simple_html_dom.php'); 

$url = 'http://wap.ebay.com/Pages/ViewItem.aspx?aid=160585148382'; 
$ch = curl_init($url); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$curl_scraped_page = curl_exec($ch); 
curl_close($ch); 

//echo $curl_scraped_page; 

$html = str_get_html($curl_scraped_page); 

// Find the img tag in the Teaser_Item div 
$a = $html->find('div[id=Teaser_Item] img', 0); 

// Display the src 
$e_image = 'http://wap.ebay.com/Pages/'.str_replace("width=57", "width=200", ($a->attr['src'])); 
echo '<img src="'.$e_image.'" /> <br /><br />'; 


$wow = $html->find('a#ButtonMenuItem3', 0); 

$descurl = 'http://wap.ebay.com'.$wow->attr['href']; 
echo $descurl; 


exit; 

$html->clear(); 
unset($html); 


$html = file_get_html($descurl); 

echo $html; 




$html->clear(); 
unset($html); 


?> 

乾杯 娜塔莎

回答

1

你是不是$的cookie設置的值,所以CURLOPT_COOKIEFILE/CURLOPT_COOKIEJAR兩者均爲NULL,所以不節能。

0
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/'; 
    session_write_close(); 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_COOKIE, $strCookie);