Php 从tumblr获取元数据

Php 从tumblr获取元数据,php,facebook-opengraph,meta,Php,Facebook Opengraph,Meta,我想把开放图元标记og:image,og:description从tumblr博客放到我网站上的数据库中。我试着用这个代码从tubmlr获取元标记 function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $

我想把开放图元标记og:image,og:description从tumblr博客放到我网站上的数据库中。我试着用这个代码从tubmlr获取元标记

function file_get_contents_curl($url) {
$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;
}
$html = file_get_contents_curl("http://www.example.com");
//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
//get and display what you need:
$title = $nodes->item(0)->nodeValue;
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description')
    $description = $meta->getAttribute('content');
if($meta->getAttribute('name') == 'keywords')
    $keywords = $meta->getAttribute('content');
}
echo "Title: $title". '<br/><br/>';
echo "Description: $description". '<br/><br/>';
echo "Keywords: $keywords";    
我知道这段代码不会得到开放图代码,但问题是它没有得到任何元。该代码在www.google.com上运行良好,但在tumblr上运行不好。 我怎样才能得到tumblr meta?
谢谢大家!

您有正在尝试的tumblr URL示例吗?因为我复制/粘贴了你的代码,使用了www.tubmlr.com,得到了标题、描述和关键字。真的吗?我尝试了www.tumblr.com,但它超时了。我不知道有什么问题。它与谷歌一起工作,例如这里是我得到的输出。标题:注册| Tumblr,描述:从任何地方发布任何内容!,定制一切,找到并追随你喜欢的东西。立即创建您自己的Tumblr博客。关键词:TumblLog、博客、tumblog、Tumblr、Tumblr、tlog、微博。如果您对此有问题,您可能希望从curl输出一些信息。看看这对你与tumblr的连接有什么影响。我尝试了curl_getinfo,但也超时了,什么也没做。有了google.com,它就完美地工作了。不知道可能是什么问题:/它工作得很好。。。我在网络托管方面遇到了问题:/非常感谢您的帮助。