获得 og:image 元属性的最佳方法是什么 [英] what is the best way to get og:image meta property
本文介绍了获得 og:image 元属性的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的网站中显示 rss 提要链接,一切顺利,但使用 file_get_contents()
方法获取 og:image 属性需要花费很多时间.还有其他方法可以获取元标记属性吗?
I am trying to show rss feed links in my website, All going well but its taking so much time to get og:image property by using file_get_contents()
method. Is there any other way to fetch meta tag properties?
Python 是否有助于更快地获取这些标签?
Is Python helpful to get these tags faster ?
推荐答案
这是我过去获取所有 og:tags 的方式:
This is how I used to get all the og:tags:
libxml_use_internal_errors(true);
$doc = new DomDocument();
$doc->loadHTML(file_get_contents($url));
$xpath = new DOMXPath($doc);
$query = '//*/meta[starts-with(@property, \'og:\')]';
$metas = $xpath->query($query);
foreach ($metas as $meta) {
$property = $meta->getAttribute('property');
$content = $meta->getAttribute('content');
echo '<h1>Meta '.$property.' <span>'.$content.'</span></h1>';
}
这篇关于获得 og:image 元属性的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文