Skip to content

Instantly share code, notes, and snippets.

@lstroud
Created June 5, 2014 12:17
Show Gist options
  • Save lstroud/b648bc418869785c3cc5 to your computer and use it in GitHub Desktop.
Save lstroud/b648bc418869785c3cc5 to your computer and use it in GitHub Desktop.
Download 2014 WWDC Slides (PDFs)
var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');
var auth = {
'user': 'appleid',
'pass': 'mypassword',
'sendImmediately': false
};
request.get('https://developer.apple.com/videos/wwdc/2014/', {
'auth': auth
},function (error, response, body) {
if (!error && response.statusCode == 200) {
$ = cheerio.load(body);
var links = $('a').filter(function (i, el){
return $(this).attr('href').indexOf(".pdf") > 0;
});
links.each(function(i, el){
var _href = $(this).attr('href');
var _filename = _href.replace(/\?.*$/,"").replace(/.*\//,"");
console.log("Downloading " + _filename + " ... ");
var _dest = __dirname + "/" + _filename;
var _r = request(_href, {'auth': auth}).pipe(fs.createWriteStream(_dest));
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment