我正在尝试将多个RSS Feed合并为一个并将其转换为JSON。要合并RSS源,我使用了这个包:rss-combiner
以下是我用来合并其工作的RSS源的代码:
catch
然后要将Feed转换为JSON,我使用此程序包:rss-to-json使用此代码,它可以正常工作:
async
问题是当我尝试将合并的Feed转换为JSON时,我不会使用此代码获得任何结果:
var RSSCombiner = require('rss-combiner');
var feedConfig = {
title: 'Tech news from Guardian and BBC',
size: 20,
feeds: [
'http://feeds.bbci.co.uk/news/technology/rss.xml',
'https://www.theguardian.com/uk/technology/rss'
],
pubDate: new Date()
};
RSSCombiner(feedConfig)
.then(function (combinedFeed) {
xml = combinedFeed.xml();
console.log(xml);
});
答案 0 :(得分:0)
我认为rss-to-json
要求提供网址;您正在传递XML结果。为什么不在组合RSS后使用xml2js
?
const RSSCombiner = require('rss-combiner');
const xml2js = require('xml2js');
const feedConfig = {
title: 'Tech news from Guardian and BBC',
size: 20,
feeds: [
'http://feeds.bbci.co.uk/news/technology/rss.xml',
'https://www.theguardian.com/uk/technology/rss',
],
pubDate: new Date(),
};
RSSCombiner(feedConfig)
.then((combinedFeed) => {
const xml = combinedFeed.xml();
const parser = xml2js.Parser();
parser.parseString(xml, (err, result) => {
console.log(result);
});
});