i am making a web crawler and i want to save my images in image directory of my project with their original name... let suppose after crawling i get two image where first time i get../logo.png and other time i get another image with .../glasses.png title name then i want to save my image as same title in my image folder here is my code:
var $ = cheerio.load(html);
var title = $('head title').text();
var keywords = $('head meta[name=keywords]').attr('content');
var desc = $('head meta[name=description]').attr('content');
var links = $('a');
var img = $('img').attr('src');
var request = http.get($, function(res){
var imagedata = ''
res.setEncoding('binary')
res.on('data', function(chunk){
imagedata += chunk
});
res.on('end', function(){
fs.writeFile(img, imagedata, 'binary', function(err){
if (err) throw err
console.log('File saved.')
});
});
});
any help will be appreciated