danmactough / node-feedparser

Robust RSS, Atom, and RDF feed parsing in Node.js
Other
1.97k stars 190 forks source link

Cannot parse one particular feed: "Cannot read property..." #268

Closed ghost closed 5 years ago

ghost commented 5 years ago

Node-feedparser 1.0.1 (from NPM) feedparser 2.2.9 Node 8.10

EVERY other RSS feed seems to work perfectly with Node-feedparser, but I cannot get this one to work.

https://feeds.feedburner.com/technologypodcastncbi

I've looked at the parsed feed, and I've tried:

let audioData = items.slice(0, 10).map(obj => ({
url: obj.enclosures[0].url
url: obj["media:content"]["@"].url
url: obj["rss:enclosure"]["@"].url

All give me TypeError: Cannot read property 'media:content' of undefined even though I can stringify out the object and it's fine. Weird. Is it something I'm doing wrong? Thanks

Before submitting your issue, please make sure these boxes are checked. Thank you!

rdbcci commented 5 years ago

running this: let audioData = a.map((obj,i) => {if(!obj.enclosures[0])return;console.log('%s i=%s',obj.enclosures[0].url,i)}); on returned items gives:

http://www.ncbi.ie/wp-content/uploads/podcasts/podcast_august_2018.mp3 i=0 http://www.ncbi.ie/wp-content/uploads/2018/07/GMT20180726_180201_Virtual_Te.mp3 i=1 http://www.ncbi.ie/wp-content/uploads/podcasts/podcast_july_2018.mp3 i=2 http://www.ncbi.ie/wp-content/uploads/2018/06/GMT20180628_180225_NCBI_Virtu.mp3 i=3 http://www.ncbi.ie/wp-content/uploads/podcasts/podcast_june_2018.mp3 i=5 http://www.ncbi.ie/wp-content/uploads/2018/05/GMT20180531_180303_NCBI_Virtu.mp3 i=6 http://www.ncbi.ie/wp-content/uploads/podcasts/podcast_may_2018.mp3 i=7 http://www.ncbi.ie/wp-content/uploads/podcasts/podcast_april_2018.mp3 i=8 http://www.ncbi.ie/wp-content/uploads/2018/03/GMT20180329_181148_Virtual_Te.mp3 i=9

indicating (at the time I ran it) item with index 4 had no media objects.

You need to verify the objects exist before you try to use them.

ghost commented 5 years ago

Oh, thanks so much! So it's a broken feed, nothing I'm doing wrong? Thanks for the code tip, too!

rdbcci commented 5 years ago

Feeds are very free form. Feedparser only returns what's in the feed. Just because it's supposed to be there doesn't mean it will be.

danmactough commented 5 years ago

Sounds like you're all set @digitaltoast. Thanks @rdbcci!