我正在学习节点和Casper。每次我写出该文件时,我只会得到[]。这是异步问题吗?即使我将写入内容丢到另一个then()中,也仍然是[]。
this.thenEvaluate(function () {
this.echo("we're doing stuff");
var courses = [];
var len = document.getElementsByTagName('tr').length;
for (var i = 3; i < len; i += 4) {
var c = new Object();
c.name = document.getElementsByTagName('tr')[i].getElementsByTagName('th')[0].innerText;
courses.push(c);
}
this.echo("we're writing the file now");
this.echo(courses);
fs.write(fname, JSON.stringify(courses), 'w');
});