1
我想創建一個腳本來登錄到我的Facebook帳戶,但是當我運行我的腳本時,我收到消息,未啓用Cookie。 我phantom.js腳本:試圖使用phantom.js登錄Facebook
var webPage = require('webpage');
var page = webPage.create();
page.settings.userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1';
page.settings.javascriptEnabled = true;
page.settings.loadImages = false;
phantom.cookiesEnabled = true;
phantom.javascriptEnabled = true;
page.open("http://facebook.com", function(status) {
if (status === "success") {
page.evaluate(function() {
document.querySelector("input[name='email']").value = "x";
document.querySelector("input[name='pass']").value = "y";
document.querySelector("#login_form").submit();
console.log("Login submitted!");
});
window.setTimeout(function() {
page.render('colorwheel.png');
phantom.exit();
}, 5000);
}
});
我做錯了什麼?
也許不會使用ie6作爲用戶代理? –
@Daniel A. White我嘗試與其他用戶代理,並收到相同的錯誤。 – lolix
@lolix你運行PhantomJS選項來保存cookie嗎? --cookies-file =/path/to/cookies.txt指定存儲持久Cookies的文件名(http://phantomjs.org/api/command-line.html)。 –