本文介绍了将变量传递到page.evaluate-PhantomJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在页面中传递变量.下面以我的情况进行评估?
Is it possible to pass variables in a page.evaluate in my case below?
function myFunction(webpage, arg1, arg2){
var page = require('webpage').create();
page.viewportSize = { width: 1920, height: 1080 };
page.open(webpage, function (status){
if (status == 'success') {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js", function(){
page.evaluate(function(){
arg = arg1 + arg2;
console.log(arg);
});
});
}
else { phantom.exit(); }
});
}
我尝试了几种在Internet上找到的方法,但实际上并没有什么方法可以获取其变量.
I tried several methods found on the internet but nothing actually impossible to get to its variables.
在此先感谢您的帮助:)
Thank you in advance for your help :)
推荐答案
与往常一样,evaluate函数的>文档:
As usual, the answer is clearly stated in the documentation of evaluate
function:
下面的示例演示了用法:
The example that follows demonstrates the usage:
var title = page.evaluate(function(s) {
return document.querySelector(s).innerText;
}, 'title');
console.log(title);
这篇关于将变量传递到page.evaluate-PhantomJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!