Skip to content

Instantly share code, notes, and snippets.

@kalinchernev
Last active January 1, 2022 23:12
Show Gist options
  • Save kalinchernev/5f67405d46914897ee8ff95b46b55898 to your computer and use it in GitHub Desktop.
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
#!/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