admin管理员组

文章数量:1241128

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?

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?

Share Improve this question asked Jan 24, 2014 at 18:00 whizvidswhizvids 2482 silver badges8 bronze badges 2
  • Maybe this link could help : darrendev.blogspot.fr/2013/11/… – Brice Favre Commented Jan 25, 2014 at 20:04
  • 1 possible duplicate of Write results into a file using Casper JS – Brice Favre Commented Jan 25, 2014 at 20:05
Add a ment  | 

2 Answers 2

Reset to default 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();

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

本文标签: javascriptDumping Source Code into a local file using CasperJSStack Overflow