Last active
January 1, 2022 23:12
-
-
Save kalinchernev/5f67405d46914897ee8ff95b46b55898 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'; | |
var https = require('https'); | |
var cheerio = require('cheerio'); | |
var base = 'https://www.packtpub.com/' | |
var freeEbookURL = base + 'packt/offers/free-learning'; | |
console.time('checking free ebook'); | |
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}.`); | |
console.timeEnd('checking free ebook'); | |
} | |
}); | |
}).on('error', (e) => { | |
console.error(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment