Javascript CasperJS绑定问题
我正试图进入instagram页面,但运气不好。我不断得到错误和一张空白截图 错误文本:Javascript CasperJS绑定问题,javascript,phantomjs,instagram,casperjs,Javascript,Phantomjs,Instagram,Casperjs,我正试图进入instagram页面,但运气不好。我不断得到错误和一张空白截图 错误文本: TypeError: 'undefined' is not a function (evaluating 'a.createDescriptor.bind(null,t)') Casperjs——版本是1.1.0-beta3 基本上,我使用以下代码: var casper = require('casper').create({ verbose: true, logLevel: 'debu
TypeError: 'undefined' is not a function (evaluating 'a.createDescriptor.bind(null,t)')
Casperjs——版本是1.1.0-beta3
基本上,我使用以下代码:
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
},
loadPlugins: true
});
casper.on( 'page.error', function (msg, trace) {
this.echo( 'Error: ' + msg, 'ERROR' );
});
casper.start('http://instagram.com/hello', function() {
casper.wait(3000, function() {
this.capture('screen.png');
});
});
casper.run(function() {
this.exit();
});
如果使用PhantomJS 2,则不再需要下面的垫片。遗憾的是CasperJS 1.1-beta3还不支持它,因此您可能希望使用来自的主分支
问题是PhantomJSV1.x不支持
函数.prototype.bind
。您需要为此添加一个垫片。在CasperJS中,它进入事件处理程序。在instragram上对我很有效:
casper.on( 'page.initialized', function(){
this.evaluate(function(){
var isFunction = function(o) {
return typeof o == 'function';
};
var bind,
slice = [].slice,
proto = Function.prototype,
featureMap;
featureMap = {
'function-bind': 'bind'
};
function has(feature) {
var prop = featureMap[feature];
return isFunction(proto[prop]);
}
// check for missing features
if (!has('function-bind')) {
// adapted from Mozilla Developer Network example at
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
bind = function bind(obj) {
var args = slice.call(arguments, 1),
self = this,
nop = function() {
},
bound = function() {
return self.apply(this instanceof nop ? this : (obj || {}), args.concat(slice.call(arguments)));
};
nop.prototype = this.prototype || {}; // Firefox cries sometimes if prototype is undefined
bound.prototype = new nop();
return bound;
};
proto.bind = bind;
}
});
});
如果将垫片导出到其自己的文件中并通过选项包含,则该选项不起作用,因为这些垫片是在instagram javascript之后追加的,这太晚了
注册到事件也可能起作用
还有一个纯粹的PhantomJS问题:非常感谢您的回答,这个答案在facebook上也很有效。您可能希望将PhantomJS更新到第2版,并使用GitHub上主分支的CasperJS。哦,谢谢,这会使此解决方案变得不必要吗?是的,它会使其不必要,但正如我所说,目前存在一些障碍,因为目前没有支持PhantomJS 2的CasperJS版本。只想为google添加一些标记,以防其他人搜索错误的东西(就像我一样)CasperJS casper没有呈现svg png透明png没有捕获任何捕获