gpt4 book ai didi

javascript - PhantomJS/Javascript : write to file instead of to console

转载 作者:行者123 更新时间:2023-12-03 01:54:37 25 4
gpt4 key购买 nike

从 PhantomJS 中,如何写入日志而不是控制台?

在示例中 https://github.com/ariya/phantomjs/wiki/Examples ,它总是(在我看过的那些中)这样说:

console.log('some stuff I wrote');

这不太有用。

最佳答案

以下可以通过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();

当出现一些警告或异常时,user984003 的回答中的命令会失败。有时不符合我们的特定要求,因为在某些代码库中我总是收到以下消息,该消息也将记录到该文件中。

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

关于javascript - PhantomJS/Javascript : write to file instead of to console,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15654283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com