我正在尝试基于 simplePie 解析 RSS,而我要解析的 RSS 基于 RDF。
并有一些特定的领域,如:“创造者”/“标识符”/等等......
我根据如何从 rss 中获取特定字段阅读了 simplePie 文档并编写了以下代码(与 simplePie 示例基本相同):
simplePie 文档链接:
http://simplepie.org/wiki/reference/simplepie_item/get_item_tags
$feed = new SimplePie();
$feed->set_feed_url('http://www.nature.com/nchem/current_issue/rss');
$feed->enable_cache(false);
$success = $feed->init();
//$feed->handle_content_type('text/plain');
if ($success)
{
if ($item = $feed->get_item(0))
{
// This is probably a bad example because we already support <media:content> natively, but it shows you how to parse through the nodes.
$media_group = $item->get_item_tags('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf');
$media_content = $media_group[0]['child']['http://www.w3.org/1999/02/22-rdf-syntax-ns#']['content'];
// $file = $media_content[0]['attribs']['']['url'];
// echo $file;
}
else
{
echo 'Error: Could not get first item';
}
}
else
{
echo $feed->error();
}
media_group 和 media_content(当然)总是返回 NULL
如何从 RSS 获取特定字段?