【发布时间】:2013-01-13 03:59:10
【问题描述】:
这里很有趣,我使用 injectJs 将外部文件 (site.js) 加载到我的 phantomJs/CasperJs 脚本中。它的加载很好,但函数没有评估并且作为字符串返回。
这里是 site.js:
var site = function(){
this.getName = function(){
return 'this is a name';
}
}
这是我的 phantom.js 脚本:
casper.start();
casper.then(function(){
phantom.injectJs('/path/to/site.js');
mysite = new site(casper);
name = mysite.getName;
this.echo(name);
});
我希望控制台打印出:“这是一个名字”, 但它会打印出: 'function(){ this.getName = function(){ return 'this is a name'; }}'
我也试过 eval() 无济于事(eval?)。
感谢您的帮助。
【问题讨论】:
标签: javascript server-side phantomjs casperjs