Node.js 无法在PhantomJS脚本中加载'cheerio'

Node.js 无法在PhantomJS脚本中加载'cheerio',node.js,phantomjs,cheerio,Node.js,Phantomjs,Cheerio,我在Mac上使用节点版本4.8.1(自制安装)、PhantomJS版本2.1.1和cheerio@0.22.0 现在如果我需要像这样的phantomjs脚本中的cheerio // myscript.js var cheerio = require('cheerio'); console.log("done"); 然后用 然后我会得到这个错误: TypeError: Object is not a constructor (evaluating 'require("inherits")(Pa

我在Mac上使用节点版本4.8.1(自制安装)、PhantomJS版本2.1.1和cheerio@0.22.0

现在如果我需要像这样的phantomjs脚本中的cheerio

// myscript.js
var cheerio = require('cheerio');
console.log("done");
然后用

然后我会得到这个错误:

TypeError: Object is not a constructor 
(evaluating 'require("inherits")(Parser, require("events").EventEmitter)')

phantomjs://platform/Parser.js:124
我可以用幻影做各种各样的事情。我唯一做不到的就是用cheerio


我有没有办法让cheerio在PhantomJS中工作?或者ChereIO的替代品可以工作?

ChereIO是一个node.js模块,但PhantomJS不是node.js。由于ChereIO是“服务器的jQuery”,您实际上可以将真实的jQuery与Phantom一起使用,并将其包含到您的目标页面中:

TypeError: Object is not a constructor 
(evaluating 'require("inherits")(Parser, require("events").EventEmitter)')

phantomjs://platform/Parser.js:124
page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', 
function() {
(page.evaluate(function() {
  // jQuery is loaded, now manipulate the DOM
  var $loginForm = $('form#login');
      $loginForm.find('input[name="username"]').value('phantomjs');
      $loginForm.find('input[name="password"]').value('c45p3r');
    }))
  }
);