PhantomJS令人难以置信的慢,节点进程有CPU在100%

我只是为了看看它是如何工作,看起来是超慢,并在运行时钉住CPU。 我觉得我一定在做错事。 我觉得我的代码不应该钉住CPU,只需要几秒钟的运行,但最终会花费20多秒。 我的代码和输出如下。

var phantom = require('phantom'); const startTime = new Date().getTime(); let page = null; function gimmeTime() { return new Date().getTime(); } phantom.create(['--ignore-ssl-errors=yes', '--load-images=no'], { phantomPath: './node_modules/phantomjs-prebuilt/bin/phantomjs' }) .then(instance => { phInstance = instance; return instance.createPage(); }) .then(p => { console.log(gimmeTime() - startTime); page = p; return page.open("http://www.slickdeals.com/"); }) .then(status => { console.log(gimmeTime() - startTime); return page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js'); }) .then(status => { console.log(gimmeTime() - startTime); return page.evaluate(function() { return href = 'http://slickdeals.com' + $('.fpGridBox:first .itemImageLink').attr('href'); }); }) .then(href => { console.log(gimmeTime() - startTime); console.log('href is', href); return page.open(href); }) .then(status => { console.log(gimmeTime() - startTime); return page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js'); }) .then(status => { console.log(gimmeTime() - startTime); return page.evaluate(function() { return $('title').text(); }); }) .then(author => { console.log(author); console.log(gimmeTime() - startTime); phInstance.exit(); return false; }) .catch(error => { console.log(error); phInstance.exit(); }); 

输出:

 436 6617 15921 15955 href is http://slickdeals.com/f/9159375-10-lb-musclepharm-combat-protein-powder-cookies-n-cream-60?src=featured-12075 15965 22150 Slickdeals: The Best Deals, Coupons, Promo Codes & Discounts 22163 

运行:Mac OS Node:7.2 Phantomjs:2.1.1 Phantom:3.1