我正在尝试使用 phantom.js 编写一个网络蜘蛛。但是我收到了很多错误消息,我不知道为什么。我的代码如下所示:
使用 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
我可以在最后一行得到结果,但是上面显示了很多错误,这是什么原因?