如何下载Facebook页面? [英] How to download Facebook page?

查看:189
本文介绍了如何下载Facebook页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PHP下载Facebook网页。我试过了file_get_contents和stream_context_create。我也尝试过卷曲。但是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我错过了什么吗?

Am I missing anything?

这里是卷曲代码:

       $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";


推荐答案

使用API​​代替?

您提到的URL的数据也可以从以下网址中检索:

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'));

这篇关于如何下载Facebook页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆