我试图通过下面的PHP函数获取网站的Meta标题。它适用于所有网站,但Facebook,我得到这个这个错误:
“更新浏览器|Facebook”
function fetchMeta($url)
{
$ch = curl_init();
$header = array();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $urlX);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$sites_html = fetchMeta("https://www.facebook.com/stackexchange");
echo $sites_html;
字符串
我需要改变什么才能让它工作?
2条答案
按热度按时间3hvapo4f1#
尝试发送您的用户代理与它,现在,因为它的空白(或cURL的默认)
字符串
Facebook检测到您正在使用不受支持的/旧的浏览器,因为它无法检测到现代用户代理。
gab6jxml2#
字符串