php
  • curl
  • 2010-04-01 62 views 0 likes 
    0

    設置cookie的我正在獲取somesite網頁..我如何能在捲曲

    但它什麼都不顯示 和URL地址的變化。

    比如我有捲曲頁面鍵入

    http://localhost/sushant/EXAMPLE_ROUGH/curl.php

    我的編碼是=

    $fp = fopen("cookie.txt", "w"); 
    
    fclose($fp); 
    
    $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); 
    // 2. set the options, including the url 
    
    curl_setopt($ch, CURLOPT_URL, "http://www.fnacspectacles.com/place-spectacle/manifestation/Grand-spectacle-LE-ROI-LION-ROI4.htm"); 
    
    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"); 
    // 3. execute and fetch the resulting HTML output 
    
    if(curl_exec($ch) === false) 
    { 
        echo 'Curl error: ' . curl_error($ch); 
    } 
    else 
        echo $output = curl_exec($ch); 
    
    // 4. free up the curl handle 
    curl_close($ch); 
    

    但canege URL這樣的..

    http://localhost/aide.do?sht=_aide_cookies_

    對象不找到。

    如何解決這些問題幫助我

    +0

    我不明白什麼是 「cookie.txt」 一樣。使錯誤顯示:'error_reporting(E_ALL);' – 2010-04-01 11:54:34

    +0

    你的問題到底是什麼?什麼不行? – 2010-04-01 11:54:43

    +0

    不明白爲什麼VolkerK恢復我的編輯... – 2010-04-01 11:57:46

    回答

    0

    它看起來像你都試圖保存cookies來cookie.txt的,並從那裏閱讀。您通常會做的是您訪問的第一個網址,您將curl保存爲文件。然後,針對後續請求,您提供該文件。

    我不知道的PHP方面,但來自卷邊方面,它看起來像你試圖讀取並不存在一個cookie文件。

    編輯:哦,如果你只是做一個請求,你應該甚至不需要餅乾。

    0

    好像有JavaScript中的輸出,這是造成重定向。

    所以對於測試的目的,而不是使用:

    echo $output = curl_exec($ch); 
    

    用途:

    $output = curl_exec($ch); 
    echo strip_tags($output); 
    

    更新:

    下面的代碼就會把內容插入的contents.htm ..一切ü需要pasring應該在那裏和輸出變量。

    if(curl_exec($ch) === false) 
    { 
        echo 'Curl error: ' . curl_error($ch); 
    } 
    else{ 
        $output = curl_exec($ch); 
        $fp2 = fopen("content.htm" , "w"); 
        fwrite($fp2 , $output); 
    fclose($fp2); 
    } 
    
    +0

    它只有JavaScript顯示。頁面未被收集。 plesae幫我 – 2010-04-02 15:47:55

    +0

    我更新了帖子 – 2010-04-02 17:53:03

    相關問題