【发布时间】:2016-12-14 11:02:45
【问题描述】:
我正在尝试从外部页面链接源获取标题、描述。当我试图获取 Facebook 页面源并返回另一个页面的源代码时,这不起作用。它正在其他网站上运行,如谷歌等。这是我在 PHP 中的代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public function previewLink(){
$url = "https://www.facebook.com/NASA/";
$html = $this->file_get_contents_curl($url);
$title = "";
$description ="";
$image = "";
//parsing begins here:
$doc = new \DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue();
}
我不知道我面临的问题是什么。有人可以提出一些建议吗?提前致谢。
【问题讨论】: