Skip to content

Instantly share code, notes, and snippets.

Created November 15, 2014 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f103fa5d4815f1c3a8b3 to your computer and use it in GitHub Desktop.
Save anonymous/f103fa5d4815f1c3a8b3 to your computer and use it in GitHub Desktop.
var urls = [];
var linkedname = [];
// var count = "";
$('a').each(function(i, elem) {
urls[i] = $(this).attr('href');
console.log(urls[i]);
linkedname[i] = $(this).text();
// count = urls.length;
if (urls[i].indexOf('http')!=-1)
{
urls[i];
}
else
{
urls[i] = url+urls[i];
}
reqi(urls[i], function (error, resp, body) {
if (!error && resp.statusCode == 200) {
var linkedfilename = linkedname[i] + chance.natural({min: 1, max: 100});
console.log(linkedfilename);
fs.writeFile( linkedfilename + '.html', body, function(err){
if(err){
console.log(err);
response.end(err);
return;
}
else{
console.log("Again file" + linkedfilename + "written");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment