2012-08-08 38 views
1

我做不知道自己做错了什么在这里...使用CasperJS userAgent功能的正确方法是什么?

我的代码:

var casper = require('casper').create({ 
    verbose: true, 
    stepTimeout: 10000, 
    onError: function() { 
     this.captureSelector('error.png', 'html'); 
    }, 
    logLevel: "debug" 
}); 

casper.start(); 

casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); 

casper.setHttpAuth('user', 'pass'); 

casper.thenOpen('https://www.google.com'); 

casper.then(function() { 
    this.echo(this.getCurrentUrl()); 
    currentPage = this.getTitle(); 
    this.captureSelector(currentPage + '.png', 'html'); 
});         

casper.run(); 

我的错误:

$ casperjs test.js 
[info] [phantom] Starting... 
FAIL TypeError: 'undefined' is not a function (evaluating 'casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)')') 
# type: uncaughtError 
# error: "TypeError: 'undefined' is not a function (evaluating 'casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)')')" 
TypeError: 'undefined' is not a function (evaluating 'casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)')') 
+0

看起来你使用的是casperjs的旧版本,当时没有'userAgent()' - 你的脚本可以使用casperjs最新版的master:https://gist.github.com/3303161 – NiKo 2012-08-09 10:42:45

+0

谢谢,已更新,它的工作很棒! – jnthnclrk 2012-08-09 12:36:18

回答

2

刚刚关闭的问题,它的CasperJS版本的问题。这里没有任何错误(请参阅原始海报@Niko和@jnthnclrk的问题评论)。

相关问题