【问题标题】:How to get the Full Entry in a RSS 2.0 feed如何在 RSS 2.0 提要中获取完整条目
【发布时间】:2010-10-03 05:36:24
【问题描述】:

我使用了人们建议的几种不同的脚本来尝试解析 RSS,包括 Magpie 和 PHP 中的 SimpleXML 功能。但似乎没有人能很好地处理 RSS 2.0,因为他们不会把完整的内容块还给我。有没有人建议阅读 http://chacha102.com/feed/ 上的提要,并获取完整内容而不仅仅是描述?

【问题讨论】:

    标签: php rss


    【解决方案1】:

    在没有阅读任何关于 rss“内容”命名空间以及如何使用它的文档的情况下,这里有一个有效的 SimpleXML 脚本。诀窍是在检索内容时使用命名空间。

    /* the namespace of rss "content" */
    $content_ns = "http://purl.org/rss/1.0/modules/content/";
    
    /* load the file */
    $rss = file_get_contents("http://chacha102.com/feed/");
    /* create SimpleXML object */
    $xml = new SimpleXMLElement($rss);
    $root=$xml->channel; /* our root element */
    
    foreach($root->item as $item) { /* loop over every item in the channel */
        print "Description: <br>".$item->description."<br><br>";
        print "Full content: <div>";
        foreach($item->children($content_ns) as $content_node) {
            /* loop over all children in the "content" namespace */
            print $content_node."\n";
        }
        print "</div>";
    }
    

    【讨论】:

      【解决方案2】:

      你有什么现在不工作的?解析 RSS 应该是一个简单的过程。尝试从过多的库中退出,只使用一些简单的 XPath 查询或访问 PHP 中的 DOMDocument 对象。

      见:PHP DOMDocument

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多