-
-
Save netlooker/46aff00799bdcc18d4c8fe41801cb5c3 to your computer and use it in GitHub Desktop.
Fetch info about the latest item from https://www.packtpub.com/packt/offers/free-learning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict'; | |
"use latest"; | |
var https = require('https'); | |
var cheerio = require('cheerio'); | |
var base = 'https://www.packtpub.com/' | |
var freeEbookURL = base + 'packt/offers/free-learning'; | |
https.get(freeEbookURL, (res) => { | |
res.on('data', (d) => { | |
var $ = cheerio.load(d); | |
var title = $('.dotd-title').text().trim(); | |
var CAB = $('.twelve-days-claim').attr('href'); | |
if (title && CAB) { | |
console.log(`Today's free ebook from Packtpub is ${title}.`); | |
console.log(`To claim it, click here ${base + CAB}.`); | |
} | |
}); | |
}).on('error', (e) => { | |
console.error(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@neetlooker, cheerio module is a requirement and useful for web scrapping:
npm install request cheerio
Probably the same result could be achieving (and maybe more like logging in and downloading the ebook in a folder) via http://phantomjs.org/page-automation.html