我是 phantom.js 的新手,我试图在网站页面上导航,点击一个链接(调用 AJAX 函数并更改文档 HTML)与 phantom.js。
这是我的代码:
window.setTimeout(function(){
phantom.exit();
}, 120000);
var page = require('webpage').create();
page.open("http://example.com", function(status) {
if (status !== 'success') {
console.log('{"error":"Unable to load the address for page"}');
phantom.exit();
}
var action = page.evaluate(function() {
document.getElementById("anID").click();
return "clicked";
});
var results = page.evaluate(function() {
return document.documentElement.innerHTML;
});
console.log(action);
window.setInterval(function() {
console.log(results);
phantom.exit();
}, 3000);
});
Run Code Online (Sandbox Code Playgroud)
我很困惑,因为在我的“动作”函数中,click() 调用引发了重复 3 次的错误:
TypeError: 'undefined' 不是函数
phantomjs://webpage.evaluate():3 phantomjs://webpage.evaluate():1
ph.js:121 nullTypeError: 'undefined' 不是函数
phantomjs://webpage.evaluate():3 phantomjs://webpage.evaluate():1
ph.js:121 nullTypeError: 'undefined' 不是函数
phantomjs://webpage.evaluate():3 …