0

I'm trying to automate the image download from my company dashboard. My first idea was to use require. I found a script that works perfectly: Downloading images with node.js I get the following code:

var fs = require('fs'),
request = require('request');

var download = function(uri, filename, callback){
  request.head(uri, function(err, res, body){
    console.log('content-type:', res.headers['content-type']);
    console.log('content-length:', res.headers['content-length']);

    request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
  });
};

download('https://www.google.com/images/srpr/logo3w.png', 'google.png', function(){
  console.log('done');
});

This code works without error and downloads the example image. I modify it to add the headers (token,..) and the link of my image. The script runs without errors but my contents are undefined:

content-type: undefined
content-length: undefined
done

When I look at the image created by the script, it contains html with the error "You need to enable JavaScript to run this app.". I have no idea how I can get around this problem. Does anyone have a tip?

ZiGi
  • 1
  • `I modify it to add the headers (token,..) and the link of my image.` - what headers do you add? – Konrad Oct 20 '22 at 16:00
  • 1
    Your link probably doesn't point to the image directly, but to some landing page that relies on JS, which would be exectued when one opens the link in the browser. As your node script is not a browser, it does not execute the JS embedded in that landing page. – derpirscher Oct 20 '22 at 16:02

0 Answers0