1

我正在使用 RSS Feeds 和 WinJS 为 Windows 8 创建一个 9GAG 阅读器应用程序。

代码:

function downloadBlogFeed() {
    WinJS.xhr({ url: "http://feeds.feedburner.com/9GAG" }).then(function (rss) {
        var items = rss.responseXML.querySelectorAll("item");

        for (var n = 0; n < items.length; n++) {
            var article = {};
            article.title = items[n].querySelector("title").textContent;
            var thumbs = items[n].querySelectorAll("thumbnail");
            if (thumbs.length > 1) {
                article.thumbnail = thumbs[1].attributes.getNamedItem("url").textContent;
                article.content = items[n].textContent;
                articlesList.push(article);
            }
        }
    });
}

问题是我无法从 FeedBurner 获得 9GAG Feed。我收到此错误:

Can't load http://feeds.feedburner.com/~d/styles/itemcontent.css. An app can’t load remote web content in the local context.

我也试过改变

WinJS.xhr({ url: "http://feeds.feedburner.com/9GAG" })

WinJS.xhr({ url: "http://9gag.com/?feed=rss" })

但我收到此错误:

Exception is about to be caught by JavaScript library code at line 50, column 13 in ms-appx://7df7a30e-2f19-4f36-b368-c456fde8aabd/js/default.js
0x800a138f - JavaScript runtime error: Unable to get property 'querySelectorAll' of undefined or null reference
File: default.js

它指向这一行:

var items = rss.responseXML.querySelectorAll("item");

你能帮我,做对吗?

谢谢 !

4

2 回答 2

1

干得好:

不幸的是,有一些黑客来获取图像,但可惜它可以工作,这就是使用 3rd 方 RSS 提要的生活。

WinJS.xhr({ url: "http://feeds.feedburner.com/9GAG", responseType: 'responseXML' }).then(function (rss) {
    var items = rss.responseXML.querySelectorAll("item");

    for (var n = 0; n < items.length; n++) {
        var article = {};
        article.title = items[n].querySelector("title").textContent;
        var imageStart = items[n].textContent.indexOf('<img src="') + 11;
        var imageEnd = items[n].textContent.indexOf('"', imageStart);

        article.thumbnail = items[n].textContent.substring(imageStart, imageEnd);
        article.content = items[n].textContent;
        articlesList.push(article);
    }
});
于 2012-11-21T21:08:03.737 回答
1

9GAG RSS feed 现在已经死了,尝试使用像http://9gagrss.com/这样的镜像

于 2013-04-15T16:49:12.057 回答