Created
July 14, 2015 23:26
-
-
Save diegok/ff34be06fda166b727b0 to your computer and use it in GitHub Desktop.
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 Promise = require('promise'), | |
ua = require('request'), | |
cheerio = require('cheerio'); | |
function http_get(url) { | |
return new Promise(function(resolve, reject) { | |
ua(url, function (err, res, body) { | |
if (err) { reject(err) } | |
else { | |
resolve({ | |
body: body, | |
dom: cheerio.load( body, { normalizeWhitespace: true } ), | |
res: res, | |
success: function(){ return this.res.statusCode === 200 } | |
}); | |
} | |
}); | |
}); | |
} | |
[ | |
'https://soysuper.com/', | |
'http://google.com/', | |
'http://elpais.com/', | |
'http://publico.es/', | |
'http://eldiario.es', | |
'http://xxx.es', | |
'http://kupkup.com/' | |
].forEach(function(url){ | |
http_get(url) | |
.then(function(tx){ | |
if ( tx.success() ) { console.log( tx.dom('title').text() ) } | |
else { console.error("%s [%d]", url, tx.res.statusCode ) } | |
}) | |
.catch(function(err){ | |
console.error("%s [%s]", url, err); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment