Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pdehaan/fetch-site-rss
Fetch a site's RSS feed.
https://github.com/pdehaan/fetch-site-rss
Last synced: about 1 month ago
JSON representation
Fetch a site's RSS feed.
- Host: GitHub
- URL: https://github.com/pdehaan/fetch-site-rss
- Owner: pdehaan
- License: other
- Created: 2016-09-06T17:03:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-06T18:18:16.000Z (over 8 years ago)
- Last Synced: 2024-12-01T09:09:28.715Z (about 2 months ago)
- Language: JavaScript
- Homepage: http://npm.im/fetch-site-rss
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fetch-site-rss
Fetch a site's RSS feed.
## Why?
... because you only know a site's homepage (ie: http://nytimes.com), but you want to fetch that site's RSS feed. Basically just a cheap wrapper around [**cheerio**](http://npm.im/cheerio) and [**simple-rss**](http://npm.im/simple-rss).
## Installation:
```sh
$ npm i fetch-site-rss -S
```## Usage:
```js
const { getSiteRss } = require('fetch-site-rss');getSiteRss('http://www.latimes.com')
.then((feed) => {
console.log(`Found ${feed.items.length} items:`);
feed.items.forEach((item) => {
console.log(`${item.title}\n${item.permalink || item.link || item['rss:link']['#']}\n`);
})
})
.catch((err) => console.error(err.message));
```Or, if you want to proxy all the RSS feed URLs through the Metadata service, you can use the [**proxy-services**](https://github.com/pdehaan/proxy-services) module, like so:
```js
const { getSiteRss } = require('fetch-site-rss');
const { getMetadata } = require('proxy-services');const MAX_ITEMS = 20;
getSiteRss('http://www.latimes.com')
.then((feed) => {
const items = feed.items.map((item) => {
return (item.permalink || item.link || item['rss:link']['#']);
});
// Inject the original URL into the array.
items.unshift(feed.url);
return items;
})
// Make sure we only ever scrape at most 20 items (otherwise metadata proxy will reject request).
.then((items) => items.slice(0, MAX_ITEMS))
.then((items) => getMetadata(items))
.then((items) => JSON.stringify(items, null, 2))
.then((output) => console.log(output))
.catch((err) => console.error(err.message));
```