When I use download() in CasperJS, I get a file saved in the system, but the file doesn't contain the actual source code of the webpage. It just contains a link to the remote page. How can I dump the source code of webpage into a local file using CasperJs? getHTML() is also only echoing the contents onto the terminal. How to save the contents to a file?
Asked
Active
Viewed 5,824 times
7
-
Maybe this link could help : http://darrendev.blogspot.fr/2013/11/saving-downloaded-files-in-slimerjs-and.html – Brice Favre Jan 25 '14 at 20:04
-
1possible duplicate of [Write results into a file using Casper JS](http://stackoverflow.com/questions/12826596/write-results-into-a-file-using-casper-js) – Brice Favre Jan 25 '14 at 20:05
2 Answers
11
First import file system library
var fs = require('fs');
Extract html
var html = this.getHTML();
// or
var html = this.getPageContent();
Copy into a file
var f = fs.open('/path/to/your/file', 'w');
f.write(html);
f.close();

moins52
- 744
- 8
- 27
5
do just: fs.write('path/to/file', 'your string', 'w');
in this case you don't need open and close a file

slavugan
- 1,463
- 17
- 17