2013-10-05 11 views
9

मैं नीचे दिए गए कोड का उपयोग कर साइट से एक सीएसवी फ़ाइल (विज्ञापन रिपोर्ट) डाउनलोड करने का प्रयास कर रहा हूं। मुद्दा यह है कि यह एचटीएमएल पेज डाउनलोड करेगा, न कि सीएसवी फाइल। मैं तुम्हें यूआरएल के रूप में यह प्रवेश के पीछे है नहीं दे सकता है, लेकिन यह इसी तरह का मामला है जब आप नीचे दी गई यूआरएलcasperjs डाउनलोड csv फ़ाइल

http://www.mozilla.org/en-US/firefox/new/

से Firefox डाउनलोड यह GET अनुरोध है और तत्व नेटवर्क टैब का निरीक्षण जब मैं करता हूँ अनुरोध रद्द हो जाता है। मैं कैस्पर के लिए नया हूं और इस तरह के अनुरोधों को संभालने के बारे में नहीं जानता। किसी भी मदद की सराहना की जाएगी

casper.then(function() { 
    var downloadURL = ""; 

    this.evaluate(function() { 
     var downloadURL = "http://www.lijit.com"+jQuery("#dailyCSV").attr('href'); 
    }); 

    this.download(downloadURL, '/Users/Ujwal/Downloads/caspertests/stats.csv'); 
}); 

रिस्पांस हैडर

Age:0 
Cache-Control:max-age=0 
Connection:keep-alive 
Content-Disposition:attachment; filename=stats.csv 
Content-Encoding:gzip 
Content-Length:1634 
Content-Type:text/x-csv 
Date:Sat, 05 Oct 2013 15:28:21 GMT 
Expires:Sat, 05 Oct 2013 15:28:21 GMT 
P3P:CP="CUR ADM OUR NOR STA NID" 
Server:PWS/8.0.16 
Vary:Accept-Encoding 
X-Px:ms h0-s28.p9-jfk (h0-s62.p9-jfk), ms h0-s62.p9-jfk (origin>CONN) 

उत्तर

16

मेरे अपने प्रश्न का उत्तर दिया, यहाँ समाधान

संदर्भ है: https://github.com/knorrium/google-books-downloader/blob/master/gbd.js

//Download the daily csv 
casper.then(function() {  
    this.click('#dailyCSV'); 
}); 

casper.on('resource.received', function (resource) { 
    "use strict"; 
    if ((resource.url.indexOf("publisherCSV/?startDate=") !== -1)) {   
     this.echo(resource.url); 
     var url, file; 
     url = resource.url; 
     file = "stats.csv"; 
     try { 
      this.echo("Attempting to download file " + file); 
      var fs = require('fs'); 
      casper.download(resource.url, fs.workingDirectory+'/'+file); 
     } catch (e) { 
      this.echo(e); 
     } 
    } 
}); 
संबंधित मुद्दे