Phantomjs Function.prototype.bind [英] Phantomjs Function.prototype.bind
问题描述
是的,我知道. Phantomjs不支持函数绑定.但是也许我可以使用其他东西,或者说page.open
不使用bind
?好像还可以,但是有些网站
返回错误
Yes, I know that. Function bind is not supported by Phantomjs. But maybe I can use something else, or say page.open
not to use bind
? It seems to be OK, but some websites
return error
TypeError: 'undefined' is not a function (evaluating 'b.bind(a)')
之后,我写了一个简单的脚本,它只打开一个页面:
After that I wrote a simple script, which just opens a page:
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)
})
但是错误仍然存在.错误不是主要问题,但问题是获取页面内容,因为错误后页面内容未加载...
But error is still there. Error is not the main problem, but the problem is to get page content, because after error page content is not loading...
所以,我需要帮助.
P.S.问题网站为 http://vkrushelnytskiy.wix.com/aaaa
P.S. Problem website is http://vkrushelnytskiy.wix.com/aaaa
推荐答案
有一个 npm软件包,为phantomJS缺少的.bind方法加载一个polyfill .为了方便起见,在此处复制安装说明,但请单击链接获取任何更新.
There is an npm package which loads a polyfill for phantomJS's missing .bind method. Copying the installation instructions here for convenience, but follow the link for any updates.
安装
npm install --save-dev phantomjs-polyfill
用法
require('phantomjs-polyfill')
与业力一起使用 将polyfill直接包含在karma.conf的文件列表中.
Usage with Karma Include the polyfill directly in the files list of your karma.conf
...
files: [
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
...
]
...
这篇关于Phantomjs Function.prototype.bind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!