whizvids
whizvids

Reputation: 248

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?

Upvotes: 7

Views: 5840

Answers (2)

slavugan
slavugan

Reputation: 1481

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

Upvotes: 5

moins52
moins52

Reputation: 744

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();

Upvotes: 11

Related Questions