2
考虑下面的代码...PhantomJS includeJs()+嵌套评估()不工作
var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'Lisas headless browser';
page.open('http://www.httpuseragent.org', function(status) {
if (status !== 'success')
{
console.log('Unable to access network or site is down');
}else{
page.includeJs(
// Include the https version, you can change this to http if you like.
'https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js',
function() {
(page.evaluate(function() {
// jQuery is loaded, now manipulate the DOM
console.log(document.getElementById('myagent').textContent);
}))
}
);
}
phantom.exit();
});
我试图得到一些代码会是jQuery的插入,然后让我继续执行行动,但它不计算includeJs()
嗯,其实他可以使用的console.log page.evaluate内。只需要使用[page.onConsoleMessage](http://phantomjs.org/api/webpage/handler/on-console-message.html)订阅来自控制台的消息。 – Vaviloff
谢谢。我学到了新东西 - 我会更新答案。 –