2014-10-06 81 views
0

我按照与该脚本结束了casperjs一个教程:运行phantomjs和casperjs

phantom.casperPath = "/usr/local/Cellar/casperjs/"; 
phantom.injectJs(phantom.casperPath + "/bin/bootstrap.js"); 

    var utils = require('utils'); 

    var casper = require('casper').create(); 

    casper.start('http://www.google.com'); 

    casper.wait(3000,function(){ 

    this.echo(this.getTitle()); 

    }); 

    casper.then(function(){ 
    casper.exit(); 
    }); 

casper.run(); 

当我运行该脚本,我得到这个消息:

错误:无法找到模块“utils的”

phantomjs://bootstrap.js:289

phantomjs://bootstrap.js:254在需要

我正在运行mac os,它的pahntomjs和casperjs都安装成功; “CasperJS版本1.1.0-beta3位于/usr/local/Cellar/casperjs/1.1-beta3/libexec,使用phantomjs版本1.9.7”

+0

如果您不需要使用utils,脚本是否可以工作?你用什么命令来运行它? – 2014-10-06 10:57:09

+0

我运行此命令 “phantomjs casperTest.js” 无需utils的我得到这个消息: 错误:无法找到模块 '卡斯帕' phantomjs://bootstrap.js:289个 phantomjs://bootstrap.js:254在需要 – user3017884 2014-10-06 11:49:08

+0

因此,没有一个模块可以访问。注入引导程序之前注册到['onError'](http://phantomjs.org/api/phantom/handler/on-error.html)处理程序,以查看它是否实际上是引导程序代码的问题。 – 2014-10-06 11:53:36

回答

0

您应该在phantom.casperPath结束时删除/

1

您是否安装了phantomjs的所有pre-reqs?

软件包的CentOS:

gcc gcc-c++ make flex bison gperf ruby \ 
    openssl-devel freetype-devel fontconfig-devel libicu-devel sqlite-devel \ 
    libpng-devel libjpeg-devel 

Ubuntu的软件包:

build-essential g++ flex bison gperf ruby perl \ 
    libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev \ 
    libpng-dev libjpeg-dev 

为什么你需要注入引导? Phantomjs在运行时总是使用bootstrap.js,因此除非在此文件中进行一些更改,否则可以将其删除。