Comments (6)
There's an example in a test.
Basically, call new FeedMe(true)
, and wait for the "done" event where you can call parser.done()
.
from feedme.js.
Thanks for you swift response, @fent! I'm sorry I don't think I get you. What do you mean by "wait for the "done" event where you can call parser.done()"?
Basically, what I'd like to do is to get the first 4 items in this feed http://feeds.bbci.co.uk/mundo/rss.xml. But at the moment, I got all the items. What do you think is the best way of doing it?
Here's my code:
var http = require('http');
var FeedMe = require('feedme');
var url = 'http://feeds.bbci.co.uk/mundo/rss.xml';
var parser = new FeedMe(true);
parser.on('item', function(item) {
console.log(item);
});
parser.on('end', function() {
console.log('end');
});
http.get(url, function(res) {
res.pipe(parser);
});
from feedme.js.
What do you mean by "wait for the "done" event where you can call parser.done()"?
What I mean is call .done()
inside of the event callback.
parser.on('end', function() {
var items = parser.done();
});
But if you only want the first 4 items, you'll probably want to listen for the first 4 "item" events.
from feedme.js.
Thanks a lot @fent! That was helpful. So I tweaked the code as you suggested (see following):
var http = require('http');
var FeedMe = require('feedme');
var url = 'http://feeds.bbci.co.uk/mundo/rss.xml';
var parser = new FeedMe(true);
parser.on('item', function(item) {
//console.log(item);
});
parser.on('end', function() {
var items = parser.done();
console.log(items);
});
http.get(url, function(res) {
res.pipe(parser);
});
But I cannot get the full object, missing guid
and media thumbnail
. They were shown as [object]. Is it possible to get them? Here's the incompleteconsole.log(items)
:
{ type: 'rss 2.0',
title: 'BBC Mundo - Noticias',
description: 'BBC Mundo - Noticias',
link: 'http://www.bbcmundo.com',
image:
{ url: 'http://www.bbc.co.uk/mundo/images/gel/rss_logo.gif',
title: 'BBC Mundo - Noticias',
link: 'http://www.bbcmundo.com' },
generator: 'RSS for Node',
lastbuilddate: 'Wed, 04 May 2016 17:52:35 GMT',
copyright: 'Derechos Reservados de la British Broadcasting Corporation (Corporación Británica de Radiodifusión) ',
language: 'es',
managingeditor: '[email protected]',
ttl: '15',
items:
[ { title: '¿Qué tan probable es que el millonario Donald Trump llegue a ser presidente de Estados Unidos?',
description: 'El magnate será previsiblemente el candidato del Partido Republicano en las presidenciales de noviembre. Hace un año parecía imposible que ocupara la Casa Blanca. Pero ahora ya no.',
link: 'http://www.bbc.com/mundo/noticias/2016/05/160503_internacional_elecciones_estados_unidos_donald_trump_dgm',
guid: [Object],
pubdate: 'Wed, 04 May 2016 06:44:18 GMT',
'media:thumbnail': [Object] },
{ title: 'Las 5 familias más ricas de América Latina',
description: 'Algunos de sus apellidos son conocidos y muchas tienen un punto en común: sus negocios están relacionados con una mega empresa cervecera que les ha ayudado a aumentar sus fortunas a niveles estratosféricos.',
link: 'http://www.bbc.com/mundo/noticias/2016/05/160503_economia_dinastias_familiares_mas_ricas_america_latina',
guid: [Object],
pubdate: 'Tue, 03 May 2016 22:30:26 GMT',
'media:thumbnail': [Object] },
...
] }
from feedme.js.
I've also tried to get the first 4 items with this code, but it doesn't work. What do you mean by "listen for the first 4 item events"? Thanks again!
var http = require('http');
var FeedMe = require('feedme');
var url = 'http://feeds.bbci.co.uk/mundo/rss.xml';
var parser = new FeedMe(true);
parser.on('item', function(item) {
var counter = 0;
counter++;
if (counter===4) {
parser.emit('end');
console.log(item);
}
});
parser.on('end', function() {
var items = parser.done();
//console.log(items);
});
http.get(url, function(res) {
res.pipe(parser);
});
from feedme.js.
guid
and media:thumbnail
are there, but console.log()
has a limited depth of what it will print in a terminal. Use console.dir()
if you want more depth.
from feedme.js.
Related Issues (18)
- 'end' event emitted twice HOT 4
- item description returns an object HOT 3
- [doc] end of parsing event + remote url HOT 9
- possible EventEmitter memory leak detected. HOT 5
- Unable to parse Atom feed. HOT 5
- parser.done() doens't resolve to a function HOT 1
- Crashes on way to many RSS links HOT 1
- Fails to parse some RSS2 HOT 2
- TypeError: parser.close is not a function HOT 5
- Proposed upstream API change
- An in-range update of mocha is breaking the build 🚨 HOT 2
- Error parsing JSON Feed HOT 4
- Error: Feed type not recognized HOT 1
- Error: Feed type not recognized (different from #20) HOT 1
- Version 10 of node.js has been released
- Error: Feed type not recognized HOT 1
- Error: status code 301 at ClientRequest.<anonymous> (src\rss_feeds\rss_feeds.controller.ts:38:23) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feedme.js.