无法获得9GAG Feed

时间:2012-11-21 20:23:11

标签: javascript windows-8 rss winjs feedburner

我正在使用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");

你能帮助我,做对吗?

谢谢!

2 个答案:

答案 0 :(得分:1)

你走了:

不幸的是,有一些黑客可以获取图像但是它有效,例如生活中有第三方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);
    }
});

答案 1 :(得分:1)

9GAG RSS Feed现已消失,请尝试使用像http://9gagrss.com/

这样的镜像