当使用Nightmare.js或phantom.js来抓取网站时,为什么会显示幻像出现错误

我试图用phantom.js编写一个web-spider。 但是,我收到了很多错误信息,我不知道为什么。 我的代码如下所示:

  • 使用Nightmare.js

    var Nightmare = require('nightmare'); new Nightmare() .goto('http://www.amazon.com/Aroma-Housewares-ASP-137-3-Quart-Super/dp/B00024JQ3Q') .evaluate( function(){ return document.getElementById('priceblock_ourprice').textContent; }, function( numAnchors ){ console.log(numAnchors); }) .run(); 
  • 使用phantom.js

     var page = require('webpage').create(); console.log('The default user agent is ' + page.settings.userAgent); page.open('http://www.amazon.com/Aroma-Housewares-ASP-137-3-Quart-Super/dp/B00024JQ3Q', function(status) { if (status !== 'success') { console.log('Unable to access network'); } else { var ua = page.evaluate(function() { return document.getElementById('priceblock_ourprice').textContent; }); console.log(ua); } phantom.exit(); }); 

错误消息是相同的:

 phantom stdout: ReferenceError: Can't find variable: ue....... ........ ........ phantom stdout: TypeError: 'null' is not an object (evaluating 'old_error_handler.apply') ....... $35.99 

我可以在最后一行得到结果,但上面显示的错误太多了,原因是什么?

这将会发生很多。 当前的PhantomJS(1.9.7)基于一个与Chrome 13或Safari 5相当的旧QtWebkit分支。这个页面很可能使用了PhantomJS不能理解的JavaScript语言。 大多数情况下,这是没有什么可担心的,因为该网站仍然按预期运作。