Phantomjs 错误:找不到模块';libxmljs';

Phantomjs 错误:找不到模块';libxmljs';,phantomjs,libxml-js,Phantomjs,Libxml Js,我正在尝试使用phantomjs为以下文件解析xml,documentpreviewer1.js 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

我正在尝试使用phantomjs为以下文件解析xml,
documentpreviewer1.js

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);
    }
});
Error: Cannot find module 'libxmljs'

  phantomjs://bootstrap.js:289
  phantomjs://bootstrap.js:254 in require
  documentpreivewer1.js:13
  :/modules/webpage.js:281
当我运行上面的代码时,我得到以下错误

cmd
sudo phantomjs documentpreivewer1.js

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);
    }
});
Error: Cannot find module 'libxmljs'

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

libxmljs是一个node.js模块。尽管phantomjs可以通过npm安装(不需要),但它不是node.js模块。它不与node.js共享任何内置模块(看起来相同,但不等于node.js fs)

您可以在phantomjs中使用一些node.js模块(有关相关问题,请参阅),但在phantomjs中似乎不能使用libxmljs,因为它依赖于使用
fs
path
模块的节点绑定。您必须更改实现,以便使用phantomjs功能表达所有依赖项

另一种选择可能是使用或用于casperjs node.js模块