Serve feeds from scraped HTML.
npm install scrape-to-feed
-
At the root of your project, create a
feeds
directory. This directory will contain exported modules for defining your feeds, one feed per file. -
Add a feed. Here is an example,
./feeds/nyt-example-feed.js
:
module.exports = {
url: "https://www.nytimes.com/",
handler: $ => [
{ title: "NYT example feed" },
...$(".story-heading")
.toArray()
.map(function(story) {
const $story = $(story);
return {
item: {
title: $story.text(),
link: $story.find("a").attr("href")
}
};
})
]
};
- Create and serve your feeds:
#!/usr/bin/env node
require("scrape-to-feed")();
- Your feed will be available at:
localhost:3000/nyt-example-feed
By default, all feeds will be re-scaped and rebuilt every hour. You can pass a custom interval, like so:
require("scrape-to-feed")(1000 * 60 * 60 * 24); // Update feeds once per day.