我正在使用 PhantomJS 登录 facebook。这是我的代码:
var page = require('webpage').create();
phantom.cookiesEnabled = true;
page.open("http://www.facebook.com/login.php", function(status) {
if (status === "success") {
page.evaluate(function() {
document.getElementById("email").value = "email";
document.getElementById("pass").value = "pass";
document.getElementById("loginbutton").click();
});
window.setTimeout(function() {
page.render("page.png");
phantom.exit();
}, 5000);
}
});
page.open("https://www.facebook.com/myprofil", function(status) {
window.setTimeout(function() {
page.render("profil.png");
phantom.exit();
}, 5000);
});
Run Code Online (Sandbox Code Playgroud)
到目前为止,登录过程一切顺利,但我没有找到正确的方法来访问我的个人资料 URL,例如在同一会话中。我尝试再次使用 page.open,但我不断收到带有我请求的页面的登录表单,就好像我以前从未登录过一样。在会话中导航的正确方法是什么?