Skip to content Skip to sidebar Skip to footer

Using Jsoup To Post Login Data

I'm trying to log into this website: http://deeproute.com This is my code. Connection.Response res = null; Connection homeConnection = null; Doc

Solution 1:

You need to read form before posting! You are missing param subbera=Login.


publicstaticvoidmain(String[] args)throws Exception {

    Connection.ResponseloginForm= Jsoup.connect("http://deeproute.com/deeproute/default.asp")
            .method(Connection.Method.GET)
            .execute();

    Documentdocument= Jsoup.connect("http://deeproute.com/deeproute/default.asp")
            .data("cookieexists", "false")
            .data("name", "username")
            .data("password", "pass")
            .data("subbera", "Login")
            .cookies(loginForm.cookies())
            .post();

}

Solution 2:

Might be a few(many actually) months too late but i found that i had to do some web scraping where the site was designed really confusing (the site i needed to extract data from). Also had to login first to get cookie info. @MariuszS's answer was helpful but the only problem was, i wasn't sure what the expected Map/Key-Value-Pairs were supposed to be. Thanks to Javascript, i quickly retrieved the form keys and values and was able to login successfully. Here's the Javascript:

var str = "";

//the form selector i.e.//that which is to be submitted to. In//my case, i needed to submit the entire bodyvar arr = $("input[name]");

for(var i = 0, l = arr.length; i<l; i++){
str+= '.data("'+ arr[i].name +'", "'+ arr[i].value +'")'
}

Append the value of "str" to your Jsoup request before

.method(Connection.Method.GET)
.execute();

Hope this proves to be somewhat helpful like it was for me :)

Post a Comment for "Using Jsoup To Post Login Data"