Skip to content

Instantly share code, notes, and snippets.

@netlooker
Forked from kalinchernev/getFreeEbook.js
Created January 11, 2017 09:09
Show Gist options
  • Save netlooker/46aff00799bdcc18d4c8fe41801cb5c3 to your computer and use it in GitHub Desktop.
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
#!/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);
});
@jazio
Copy link

jazio commented Apr 23, 2018

@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

@drupol
Copy link

drupol commented Apr 23, 2018

Let's do it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment