2011-05-15 6 views
1

모두 호프입니다.CURL을 사용하여 세션을 관리 할 수 ​​없음

작은 도움이 필요합니다.

CURL (http://wap.ebay.com/Pages/ViewItem.aspx?aid=160585148382)으로 페이지를 긁어 내려고 시도합니다.이 페이지가로드되면 해당 페이지에 다른 링크가 있습니다 (앵커 텍스트 : 설명), 나는 그 페이지도 긁어 내고 싶다.

설명 페이지 (http://wap.ebay.com/Pages/ViewItemDesc.aspx?aid=280655395879 & emvcc = 0)로 직접 이동하면 ur 브라우저에서 '세션 만료 됨'과 같은 오류가 표시됩니다. 또는 경매 세부 정보가 발견되지 않았습니다. "라고 말하면서, 우리는 그 페이지를 긁어 내거나 세션을 가질 필요가 있다고 생각합니다.

그래서 먼저 스크래핑을하고 싶습니다. http://wap.ebay.com/Pages/ViewItem.aspx?aid=280655395879 & 그런 다음 설명 버튼에서 URL을 추출한 다음 접두사 (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

당신은 모두가 그렇게 절약 둘 NULL입니다 그래서 CURLOPT_COOKIEFILE/CURLOPT_COOKIEJAR, 값으로 $ 쿠키를 설정하지 않습니다.

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); 
관련 문제