-
-
Save spion/2a2804e43e4d33aae208 to your computer and use it in GitHub Desktop.
streams-es6.js
This file contains 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
var B = require('bluebird'), | |
request = require('request'), | |
cheerio = require('cheerio'), | |
path = require('path'), | |
fs = require('fs'); | |
B.promisifyAll(request) | |
var loadDocument = url => | |
request.getAsync(url) | |
.spread((res, body) => | |
cheerio.load(body)); | |
var download = url => | |
request(url).pipe( | |
fs.createWriteStream( | |
path.basename(url))); | |
// Download all images from an imgur page | |
var downloadAllImages = urls => | |
loadDocument(url).then($ => | |
$('.post a img').map((i, img) => | |
downloadImage(URL.resolve(url, img.attribs.src)))); | |
downloadImages('http://imgur.com/').done( | |
_ => console.log('done'), | |
e => console.error(e.stack)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment