2017-04-30 4 views
0

나는 spookyjs의 NPM 웹 페이지에서 예제 코드를 복사 한 :spookyjs

try { 
 
    var Spooky = require('spooky'); 
 
} catch (e) { 
 
    Spooky = require('node_modules/spooky'); 
 
} 
 

 
var spooky = new Spooky({ 
 
    child: { 
 
     transport: 'http' 
 
    }, 
 
    casper: { 
 
     logLevel: 'debug', 
 
     verbose: true 
 
    } 
 
}, function (err) { 
 
    if (err) { 
 
     e = new Error('Failed to initialize SpookyJS'); 
 
     e.details = err; 
 
     throw e; 
 
    } 
 

 
    spooky.start(
 
     'http://en.wikipedia.org/wiki/Spooky_the_Tuff_Little_Ghost'); 
 
    spooky.then(function() { 
 
     this.emit('hello', 'Hello, from ' + this.evaluate(function() { 
 
       return document.title; 
 
      })); 
 
    }); 
 
    spooky.run(); 
 
}); 
 

 
spooky.on('error', function (e, stack) { 
 
    console.error(e); 
 

 
    if (stack) { 
 
     console.log(stack); 
 
    } 
 
}); 
 

 

 
// Uncomment this block to see all of the things Casper has to say. 
 
// There are a lot. 
 
// He has opinions. 
 
spooky.on('console', function (line) { 
 
    console.log(line); 
 
}); 
 

 

 
spooky.on('hello', function (greeting) { 
 
    console.log(greeting); 
 
}); 
 

 
spooky.on('log', function (log) { 
 
    if (log.space === 'remote') { 
 
     console.log(log.message.replace(/ \- .*/, '')); 
 
    } 
 
});
하지만 오류가 발생합니다 :

Error: Cannot find module 

'/home/svet/WebstormProjects/nodejsStudy/studyFiles/node_modules/spooky/lib/../node_modules/tiny-jsonrpc/lib/tiny-jsonrpc' 

[ { file: 'phantomjs://platform/bootstrap.js', 
    line: 299, 
    function: 'require' }, 
    { file: 'phantomjs://platform/bootstrap.js', 
    line: 263, 
    function: 'require' }, 
    { file: 'phantomjs://platform/http-server.js', 
    line: 6, 
    function: '' } ] 
{ Error: Child terminated with non-zero exit code 1 
    at Spooky.<anonymous> 
(/home/svet/WebstormProjects/nodejsStudy/studyFiles/node_modules/spooky/lib/spooky.js:210:17) 

    at emitTwo (events.js:106:13) 
    at ChildProcess.emit (events.js:194:7) 
    at Process.ChildProcess._handle.onexit 
(internal/child_process.js:215:12) details: { code: 1, signal: null } } 

을 작은 jsonrpc 모듈이 이미 설치되어 있습니다

답변

0

해당 스크립트를 실행하기 전에 phantomjs을 설치해야합니다.
npm을 사용하여 팬텀을 설치할 수 있습니다. npm install phantomjs