When I use download () in CasperJS, I get the file saved on the system, but the file does not contain the actual source code of the web page. It just contains a link to the remote page. How can I dump the source code of a webpage to a local file using CasperJs? getHTML () also reflects only content on the terminal. How to save contents to a file?
The first import file system library
var fs = require('fs');
Extract html
var html = this.getHTML(); // or var html = this.getPageContent();
Copy to file
var f = fs.open('/path/to/your/file', 'w'); f.write(html); f.close();
simple to do: fs.write('path/to/file', 'your string', 'w');in this case you do not need to open and close the file
fs.write('path/to/file', 'your string', 'w');