1

次のファイルに対して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);
    }
});

上記のコードを実行すると、次のエラーが表示されます

コマンド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
4

1 に答える 1