Vit*_*lii 6 javascript phantomjs
对,我知道.Phantomjs不支持函数绑定.但也许我可以使用其他东西,或者说不page.open使用bind?它似乎没问题,但有些网站会返回错误
TypeError: 'undefined' is not a function (evaluating 'b.bind(a)')
Run Code Online (Sandbox Code Playgroud)
之后我写了一个简单的脚本,它只打开一个页面:
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)
})
Run Code Online (Sandbox Code Playgroud)
但错误仍然存在.错误不是主要问题,但问题是获取页面内容,因为错误页面内容未加载后...
所以,我需要帮助.
有一个npm包,可以为phantomJS缺少的.bind方法加载一个polyfill.为方便起见,请在此处复制安装说明,但请按照链接进行更新.
安装
npm install --save-dev phantomjs-polyfill
Run Code Online (Sandbox Code Playgroud)
用法
require('phantomjs-polyfill')
Run Code Online (Sandbox Code Playgroud)
与Karma一起使用 将polyfill直接包含在karma.conf的文件列表中
...
files: [
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
...
]
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4072 次 |
| 最近记录: |