我想使用 PHP 下载 Facebook 网页。我尝试过 file_get_contents 和stream_context_create。我也尝试过 curl 。但 Facebook 仅返回此消息:
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:
我错过了什么吗?
这是 Curl 代码:
$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 的数据也可以从此 URL 中检索:
http://graph.facebook.com/?id=189662541197403
此外,这会将您的整个代码减少到这一行:
json_decode(file_get_contents('http://graph.facebook.com/?id=189662541197403'));
关于php - 如何下载 Facebook 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17591273/