我目前正在使用nodejs和phantomjs(使用这个桥:https://github.com/sgentle/phantomjs-node/blob/master/samples/test_phantom.js),我的简单幻像功能不能正常工作。我想知道它是否是与phantomjs和nodejs的兼容性错误,还是我只是犯了一个明显的phantomjs错误?我想抓住谷歌主页上的输入表格。以下是相关代码:
phantom.create(function (ph) {
ph.createPage(function (page) {
page.open("https://www.google.com/", function (status) {
console.log("opened", status);
/*
Page is succesfully opened
*/
page.evaluate(function() {
var x; //meaningless code
function funny() {
var q = document.getElementById("gbqfq").value; //if q = document.title it works properly
return q;
}
x = funny();
return x;
},
function(result) {
console.log(result);
ph.exit();
});
});
});
我收到的错误:
phantom stdout: TypeError: 'null' is not an object (evualuating 'document.getElementById("gbqfq").value')
非常感谢!