node-js-libs / curlrequest

A cURL wrapper
MIT License
184 stars 44 forks source link

Downloading a file #56

Open SantoshSrinivas79 opened 7 years ago

SantoshSrinivas79 commented 7 years ago

The script works but the zip file is corrupted. What am I doing wrong here?

// curl -LOk  -X 'GET' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:51.0) Gecko/20100101 Firefox/51.0' -H 'Referer: https://nseindia.com/products/content/equities/equities/archieve_eq.htm' -H 'Upgrade-Insecure-Requests: 1' 'https://nseindia.com/content/historical/EQUITIES/2000/MAR/cm7MAR2000bhav.csv.zip'

var curl = require('curlrequest');
var fs   = require( 'fs' );

var options = {
    url: 'https://nseindia.com/content/historical/EQUITIES/2000/MAR/cm7MAR2000bhav.csv.zip',
    verbose: true,
    headers: { 
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:51.0) Gecko/20100101 Firefox/51.0',
        'Referer': 'https://nseindia.com/products/content/equities/equities/archieve_eq.htm',
        'Upgrade-Insecure-Requests': '1'    
    }
};

var file = fs.createWriteStream("bhav.zip");

curl.request(options, function (err, data) {
    file.write(data);
});