2014-07-07 3 views
1

나는 다음과 같은 파일을 phantomjs를 사용하여 XML을 구문 분석을 시도하고, documentpreviewer1.js오류 : 찾을 수 없습니다 모듈 'libxmljs'

var webPage = require('webpage'); 
var page = webPage.create(); 

var url = "http://xxx/sitemap.xml"; 

page.open(url, function(status){ 
    if(status != 'success'){ 
       console.log('Unable to access cfc'); 
    } 
    else 
    { 
       var xml = page.content; 
       var libxmljs = require("libxmljs"); 
       var xmlDoc = libxmljs.parseXml(xml); 

       var url1 = xmlDoc.get('//urlset/url[0]/loc'); 
       console.log(url1); 
    } 
}); 

나는 위의 코드를 실행할 때, 나는 다음과 같은 오류를 얻을

cmd를 sudo phantomjs documentpreivewer1.js

Error: Cannot find module 'libxmljs' 

    phantomjs://bootstrap.js:289 
    phantomjs://bootstrap.js:254 in require 
    documentpreivewer1.js:13 
    :/modules/webpage.js:281 

답변

1

libxmljs는 node.js 모듈입니다. phantomjs는 npm (설치할 필요는 없음)을 통해 설치할 수 있지만 node.js 모듈은 아닙니다. 내장 모듈을 node.js와 공유하지 않습니다 (fs은 같지만 node.js fs와 같지 않음).

당신은 phantomjs (관련 질문에 대한 Use a node module from casperjs 참조) 일부 Node.js를 모듈을 사용할 수 있지만 phantomjs에 libxmljs를 사용할 수있는 것처럼 fspath 모듈을 사용 노드 바인딩에 의존하기 때문에 그것은하지 않는 것 . 모든 의존성을 phantomjs 기능으로 표현할 수 있도록 구현을 변경해야합니다.

casperjs node.js 모듈에 phantom-node 또는 을 사용할 수도 있습니다.

관련 문제