PhantomJS / [removed] write to file instead of to console

前端 未结 3 1784
遥遥无期
遥遥无期 2021-02-01 04:45

From PhantomJS, how do I write to a log instead of to the console?

In the examples https://github.com/ariya/phantomjs/wiki/Examples, it always (in the ones I have looked

3条回答
  •  忘掉有多难
    2021-02-01 05:31

    The following can write contents to the file directly by phantomjs:

    var fs = require('fs');
       try {
        fs.write("/home/username/sampleFileName.txt", "Message to be written to the file", 'w');
        } catch(e) {
            console.log(e);
        }
        phantom.exit();
    

    The command in the answer by user984003 fails when there is some warning or exceptions occurred. And sometimes does not fall into our specific requirements because in some codebase I am getting the following message always which will also be logged to that file.

    Refused to display document because display forbidden by X-Frame-Options.
    

提交回复
热议问题