feed

node v8.17.0
version: 1.0.0
endpointsharetweet
var express = require('express'); var request = require('request'); var cheerio = require('cheerio'); var cors = require('cors'); var app = express(); var Feed = require("feed"); let feed = new Feed({ title: 'RSS feed v1', description: 'Generate RSS feed with NodeJS', //image: 'http://example.com/image.png', //favicon: 'http://example.com/favicon.ico', copyright: '', //updated: new Date(), generator: 'Awesome', // optional, default = 'Feed for Node.js' //author: {name: 'author name', email: '[email protected]', link: 'author link'} }) app.use(cors()) app.get('/', function(req, res) { url = 'http://www.photobook.com.my/promotions'; request(url, function(error, response, html){ if(!error) { console.log('success'); var $ = cheerio.load(html, {decodeEntities: false}); var json = []; $('#tab-prepaid .col').each(function(i, element){ var a = $(this); var title = a.children('.block').children('a').children('h5').text(); var link = a.children('.block').children('a').attr('href'); var img = a.children('.block').children('a').children('img').attr('src'); var description = a.children('.block').children('.prices-prepaid').text(); json.push({'title':title, 'url':url}); feed.addItem({ title: title, link: link, author: [{name: 'anonymous', email: '[email protected]', link: 'https://example.com/anonymous'}], description: '[description] '+description, content: '<a href="'+link+'"><img src="'+img+'"/></a>' + '[content] <p>'+description+'</p>', date: new Date(), image: img, }); }); var rssdoc = feed.rss2(); //res.json(json); res.send(rssdoc); } }); }); app.listen(3000, () => console.log('Example app listening on port 3000!'))
Loading…

no comments

    sign in to comment