Redirect 使用phantomjs-302问题登录Facebook?
我正试图编写一个phantomjs脚本,登录到我的facebook帐户并截图 这是我的密码:Redirect 使用phantomjs-302问题登录Facebook?,redirect,phantomjs,http-status-code-302,Redirect,Phantomjs,Http Status Code 302,我正试图编写一个phantomjs脚本,登录到我的facebook帐户并截图 这是我的密码: var page = require('webpage').create(); var system = require('system'); var stepIndex = 0; var loadInProgress = false; email = system.args[1]; password = system.args[2]; page.onLoadStarted = function()
var page = require('webpage').create();
var system = require('system');
var stepIndex = 0;
var loadInProgress = false;
email = system.args[1];
password = system.args[2];
page.onLoadStarted = function() {
loadInProgress = true;
console.log("load started");
};
page.onLoadFinished = function() {
loadInProgress = false;
console.log("load finished");
};
var steps = [
function() {
page.open("http://www.facebook.com/login.php", function(status) {
page.evaluate(function(email, password) {
document.querySelector("input[name='email']").value = email;
document.querySelector("input[name='pass']").value = password;
document.querySelector("#login_form").submit();
console.log("Login submitted!");
}, email, password);
page.render('output.png');
});
},
function() {
console.log(document.documentElement.innerHTML);
},
function() {
phantom.exit();
}
]
setInterval(function() {
if (!loadInProgress && typeof steps[stepIndex] == "function") {
console.log("step " + (stepIndex + 1));
steps[stepIndex]();
stepIndex++;
}
if (typeof steps[stepIndex] != "function") {
console.log("test complete!");
phantom.exit();
}
}, 10000);
(灵感来源于,但请注意,我已将间隔时间提高到10秒)
这样称呼:
./phantomjs test.js <email> <password>
/phantomjs test.js
通过输出(过滤掉Facebook上的selfxss警告):
步骤1
开始加载
装载完成
登录已提交!
开始加载
装载完成
步骤2
步骤3
测试
完成
(请注意,步骤2中的html输出为空)
表明phantomjs的SSL选项存在问题,但使用--SSL protocol=any
运行没有效果
这似乎是一个类似的问题,但对于caspar,而不是phantomjs(在Windows上,而不是Mac上)-我尝试使用--ignore ssl errors=yes
,但也没有效果
我猜这可能是一个重定向问题(事实上,当我在Chrome上复制这个问题时,单击“提交”得到的响应是一个302,位置https://www.facebook.com/checkpoint/?next
),但根据文档,我可以设置一个page.onNavigationRequested
处理程序——当我在脚本中这样做时,它不会被调用
我认为这个问题是相关的,但看起来似乎并没有解决办法。您无法判断它是否适用于此脚本。在page.evaluate(函数(){return document.documentElement.innerHTML;})中包装document.documentElement.innerHTML
。这似乎有效。谢谢您能解释一下为什么执行重定向需要page.evaluate(…)吗?我希望它会自动执行。重定向工作正常。只是文档
在页面上下文之外没有任何意义。
step 1
load started
load finished
Login submitted!
load started
load finished
step 2
<head></head><body></body>
step 3
test
complete!