台灣最大裝潢接案平台
輕鬆接案網
清潔公司專精高難度抓漏工程,近30年經驗
快速找出問題所在,品質絕佳。

首頁  •  tw 論壇 • 程式設計討論     • 

[php] 使用curl登入facebook抓資料

房東:威威
發表時間:2012-07-17
[檢舉]



function cURL($url, $header=NULL, $cookie=NULL, $post=NULL)

{

    //$user_agent = $_SERVER[\'HTTP_USER_AGENT\']; 

    $user_agent = \'Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2\';

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, $header);

    curl_setopt($ch, CURLOPT_NOBODY, $header);

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    curl_setopt($ch, CURLOPT_COOKIE, $cookie);

    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

       

    if ($post) {

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

        curl_setopt($ch, CURLOPT_POST, 1);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

    }

    $result = curl_exec($ch);

    $error = curl_error($ch);

    curl_close($ch);

       

    if($result){

        return $result;

    }else{

        return $error;

    }

}

   

function curl_fb($url){

    //輸入要用來登入的e-mail與密碼

    $EMAIL = "";

    $PASSWORD = "";

  


    $result = cURL($fb_login_url,true,null,"email=$EMAIL&pass=$PASSWORD");

    preg_match(\'%Set-Cookie: ([^;]+);%\',$result,$M);

    $result = cURL($fb_login_url,true,$M[1],"email=$EMAIL&pass=$PASSWORD");

    preg_match_all(\'%Set-Cookie: ([^;]+);%\',$result,$M);

      

    $cookie = \'\';

    for($i=0;$i<count($M[0]);$i++){

        $cookie .= $M[1][$i].";";

    

  

    return cURL($url,null,$cookie,null);

}

  

//要抓取的網頁顯示出來



echo curl_fb($url);


 


http://disp.cc/b/11-3agL







  • 贊助網站       

    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務
    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!



  •  共 0 人回應

    姓名:
    佈告內容: