dongshan8194 2013-07-11 10:41
浏览 231
已采纳

如何下载Facebook页面?

I want to download a Facebook web page using PHP. I've tried file_get_contents along with stream_context_create. I've also tried Curl. But Facebook is returing only this message:

Update Your Browser You’re using a web browser that isn’t supported by Facebook. To get a better experience, go to one of these sites and get the latest version of your preferred browser:

Am I missing anything?

Here is the Curl code:

       $url="https://www.facebook.com/media/set/?set=a.189662541197403.1073741845.188398434657147&type=1&l=a8755a774e";
        $custom_headers = array();
        $custom_headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        $custom_headers[] = "Pragma: no-cache";
        $custom_headers[] = "Cache-Control: no-cache";
        $custom_headers[] = "Accept-Language: en-us;q=0.7,en;q=0.3";
        $custom_headers[] = "Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.7";

        $ch = curl_init();
        $useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1";
        curl_setopt($ch, CURLOPT_USERAGENT, $useragent); // set user agent
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_headers);

        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,20);
        curl_setopt($ch, CURLOPT_TIMEOUT, 40); //timeout in seconds

        $txResult = curl_exec($ch);

        $statuscode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        print "$txResult";
  • 写回答

2条回答 默认 最新

  • dongqiangteng7319 2013-07-11 10:47
    关注

    Use the API instead?

    The data for the URL you mentioned can also be retrieved from this one:

    http://graph.facebook.com/?id=189662541197403
    

    Also, that reduces your entire code to this line :

    json_decode(file_get_contents('http://graph.facebook.com/?id=189662541197403'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?