我在localhost\administration上有一个登录页面,我使用以下代码登录:import urllib
import http.cookiejar as ckj
lg = {'nick':'john','pass':'password'}
url = 'http://localhost/administration/'
cj = ckj.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
lgdata = urllib.parse.urlencode(lg).encode("utf-8")
opener.open(url,lgdata)
res = opener.open(url)
print(res.read())
这个页面只是PHP代码。
现在我想登录到这个页面localhost:8080/pentaho/Login,但是这个页面使用javascript登录,我不知道应该如何向页面发送什么数据。在
我知道我需要url = localhost:8080/pentaho/Login和lg = {'j_username':'username','j_password':'password'},但这并不是我需要发送到操作的所有信息,或者这是不正确的。在
以下是登录表单的html代码:
^{pr2}$
这是页面的javascript
function toggleEvalPanel() {
var evaluationPanel = $("#evaluationPanel");
evaluationPanel.toggleClass("afterSlide");
$("#eval-arrow").toggleClass("closed");
}
function bounceToReturnLocation() {
// pass
var locale = document.login.locale.value;
var returnLocation = 'http\x3A\x2F\x2Flocalhost\x3A8080\x2Fpentaho\x2Findex.jsp';
if (returnLocation != '' && returnLocation != null) {
window.location.href = returnLocation;
} else {
window.location.href = window.location.href.replace("Login", "Home") + "?locale=" + locale;
}
}
function doLogin() {
// if we have a valid session and we attempt to login on top of it, the server
// will actually log us out and will not log in with the supplied credentials, you must
// login again. So instead, if they're already logged in, we bounce out of here to
// prevent confusion.
if (false) {
bounceToReturnLocation();
return false;
}
jQuery.ajax({
type: "POST",
url: "j_spring_security_check",
dataType: "text",
data: $("#login").serialize(),
error:function (xhr, ajaxOptions, thrownError){
if (xhr.status == 404) {
// if we get a 404 it means login was successful but intended resource does not exist
// just let it go - let the user get the 404
bounceToReturnLocation();
return;
}
//Fix for BISERVER-7525
//parsereerror caused by attempting to serve a complex document like a prd report in any presentation format like a .ppt
//does not necesarly mean that there was a failure in the login process, status is 200 so just let it serve the archive to the web browser.
if (xhr.status == 200 && thrownError == 'parsererror') {
document.getElementById("j_password").value = "";
bounceToReturnLocation();
return;
}
// fail
$("#loginError").show();
$("#loginError button").focus();
},
success:function(data, textStatus, jqXHR){
if (data.indexOf("j_spring_security_check") != -1) {
// fail
$("#loginError").show();
$("#loginError button").focus();
return false;
} else {
document.getElementById("j_password").value = "";
bounceToReturnLocation();
}
}
});
return false;
}
function loginAs (username, password) {
$("#j_username").attr("value", username);
$("#j_password").attr("value", password);
doLogin();
}
$(document).ready(function(){
$("#login").submit(doLogin);
if (false) {
bounceToReturnLocation();
}
$("#login-background").fadeIn(1000, function() {
$("#login-logo").addClass("afterSlide");
$("#animate-wrapper").addClass("afterSlide");
$("#j_username").focus();
$("#login-footer").addClass("afterSlide");
});
});