Reputation: 189
I'm trying to download the following csv file using casperjs
var casper = require('casper').create({});
casper.start('http://69.50.252.196/');
casper.then(function(){
this.download('http://69.50.252.196/download.csv', 'downloaded.csv');
});
casper.run(function() {
this.exit();
});
download.csv
إختبار Arabic
آزمایشی Persian
测试 Chinese
測試 Chinese
испытание Russian
परीक्षा Hindi
δοκιμή Greek, Modern (1453-)
테스트 Korean
טעסט Yiddish
テスト Japanese
பரிட்சை Tamil
but the downloaded file always corrupted and got corrupted characters
downloaded.csv
"%.*('1 Arabic"
"2E'ج4ج Persian
Kص Chinese
,f Chinese
8A?KB0=85 Russian
*0@M7> Hindi
´؟؛¹¼® Greek" Modern (1453-)"
"L¤¸ Korean"
"طâلط Yiddish"
"ئ¹ب Japanese"
"ھ°؟ںحڑب Tamil"
Help please, i cant use child_process or wget or curl file must be downloaded using casperjs
Upvotes: 3
Views: 1185
Reputation: 189
after researching casperjs modules solution found ! the issue due to base64encode of data in addition to handling binary data
Workaround till fix: I removed the encoding function and modified open file flag for wb to w
OLD casper.js
fs.write(targetPath, cu.decode(this.base64encode(url, method, data)), 'wb');
New casper.js
fs.write(targetPath, this.base64encode(url, method, data), 'w');
OLD clientutils.js
return this.encode(this.getBinary(url, method, data));
New clientutils.js
return this.getBinary(url, method, data);
Regards
Upvotes: 3
Reputation: 28913
This appears to be a PhantomJS bug. (I just upgraded from 1.9.0 to 1.9.2 to be sure: I'd hoped this bug report might have meant it was fixed in 1.9.1.)
However it does work with SlimerJS. When I run with:
casperjs --engine=slimerjs test.js
I get a 356 byte file, exactly as I do with wget (and it displays as UTF-8, correctly). With PhantomJS as the CasperJS engine I get a 177 byte file, that does not display anything useful.
Upvotes: 1