2011-05-15 48 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);