phantomjs全局变量在page.evaluate中调用
我想知道如何在phantomjs中全局使用变量,以便它也可以在page.evaluate函数中使用phantomjs全局变量在page.evaluate中调用,phantomjs,Phantomjs,我想知道如何在phantomjs中全局使用变量,以便它也可以在page.evaluate函数中使用 我已经阅读了前面的一些答案,但是能够很好地理解JSON可序列化参数可以传递给。 下面是一个使用此技术的非常基本的示例: page.open('http://stackoverflow.com/', function(status) { var title = page.evaluate(function(s) { return document.querySelector(s).in
我已经阅读了前面的一些答案,但是能够很好地理解JSON可序列化参数可以传递给。 下面是一个使用此技术的非常基本的示例:
page.open('http://stackoverflow.com/', function(status) {
var title = page.evaluate(function(s) {
return document.querySelector(s).innerText;
}, 'title');
console.log(title);
phantom.exit();
});
这为我解决了问题: