Oui, je sais que. Strong> La fonction de fonction n'est pas prise en charge par PhantOMJS. Mais peut-être que je peux utiliser quelque chose d'autre ou dire page.open code> ne pas utiliser lier code>? Cela semble être ok, mais certains sites Web
Erreur de retour var address = phantom.args[0];
if(!address) phantom.exit(1);
page = require("webpage").create();
page.open(address, function(status){
setInterval(
function () {
console.log(
page.evaluate(function() {
return document.body.innerHTML.length;
})
)}, 200)
})
4 Réponses :
vous pouvez utiliser la fonction shim.bind en utilisant ce qui suit polyfill . p>
Il suffit de la compenser au code que vous essayez de courir. Il y a probablement des solutions plus agréables, mais cela a fonctionné super pour moi. P>
You can use this code as an alternative
if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) {
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function() {},
fBound = function() {
return fToBind.apply(this instanceof fNOP
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
Vous pouvez mentionner cette fonction de liaison juste avant le cas de test.
// PhantomJS doesn't support bind yet
Function.prototype.bind = Function.prototype.bind ||
function (ctx) {
var fn = this,
args = [],
param_length = 0;
for(var i=0; i<arguments.length; i++) {
if(i){
args[i-1] = arguments[i];
}
}
param_length = args.length;
return function () {
for(var i =0; i<arguments.length; i++){
args[param_length + i] = arguments[i];
}
return fn.apply(ctx, args);
};
};
Il y a un package NPM qui charge un polyfill pour la méthode manquante de Phantomjs manquante . Copier les instructions d'installation ici pour plus de commodité, mais suivez le lien pour toutes les mises à jour.
Installation forte> p> ...
files: [
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
...
]
...
Pourquoi pensez-vous que la page se chargerait car rien n'est arrivé lorsque l'erreur Bind provient de
exiger.min.js code>?Dupliqué possible de Phantomjs page.Content ne récupère pas le contenu de la page a>
^ Je l'ai essayé avec votre URL et ça marche.
@Artjomb., Fonctionne-t-il sur la page?
@ARTJOMB. J'ai essayé et ça marche. Merci!