Fix source code in local file using CasperJS

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?

+6
source share
2 answers

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(); 
+9
source

simple to do: fs.write('path/to/file', 'your string', 'w');
in this case you do not need to open and close the file

+5
source

All Articles