当我尝试 curl www.yelp.com
时,它需要 1.1 秒。然而,使用 CasperJS 检索页面需要超过一分钟的时间!
这正常吗?我如何找出是什么在减慢 casper/phantom 的速度?我怀疑 casper 没有遵循它的某些 HTTP 重定向?
var casper = require('casper').create();
var url = 'http://www.yelp.com';
casper.start(url);
casper.then(function() {
console.log( this.getHTML() );
this.exit();
});
casper.run();
最佳答案
你在 Windows 上吗?如果是,则在使用自动代理时存在神秘的网络问题。有关详细信息,请参阅发行说明:http://phantomjs.org/release-1.9.html .
一般来说,尝试分析网络请求和响应。跟踪网络流量的一种非常简单的方法:
page.onResourceRequested = function (request) {
console.log('Request ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function (response) {
console.log('Receive ' + JSON.stringify(response, undefined, 4));
};
如果您需要时间等,您需要进一步调整它。阅读有关此 Network Monitoring 的文档特征。
关于php - CasperJS/PhantomJS 比 Curl 慢得多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15859454/