Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dumping Source Code into a local file using CasperJS

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?

like image 396
whizvids Avatar asked Jan 24 '14 18:01

whizvids


2 Answers

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();
like image 130
moins52 Avatar answered Sep 28 '22 01:09

moins52


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

like image 28
slavugan Avatar answered Sep 28 '22 02:09

slavugan