Search code examples
javaauthenticationjsoupscreen-scraping

How do I login in this specific page with Jsoup?


I've been trying to login to this page https://www.gpro.net/gb/gpro.asp with Jsoup, and I'm almost pulling all my hair out, it just doesn't work.

Here's what I've been trying:

Connection.Response loginForm = Jsoup.connect("https://www.gpro.net/gb/gpro.asp")
            .method(Connection.Method.GET)
            .execute();

           Document document = Jsoup.connect("https://www.gpro.net/gb/gpro.asp")
            .data("cookieexists", "false")
            .data("Text1", "myEmail")
            .data("Password2", "myPassword")
            .cookies(loginForm.cookies())
            .post();
           System.out.println(document);

and here's the form

<form method="post" action="Login.asp?Redirect=gpro.asp" ID="Form1" style="margin:0px">
      <h1>Quick login</h1>
      <div class="inner">

        <label for="textLogin">Username or Email address:</label>
        <input type="text" name="textLogin" value="" class="texty" ID="Text1">
        <label for="textLogin">Password:</label>
        <input type="password" name="textPassword" class="texty" ID="Password2">
        <input type="hidden" name="token" value="" ID="token">
        <input type="hidden" name="Logon" value="Login" ID="Hidden1">
        <input type="submit" name="LogonFake" value="Login" class="halo micro" ID="Submit2">
        <a href="LostPassword.asp" class="password">Forgotten your password?</a>        
        <div class="center" style="clear:both; float:left; width:100%; text-align:center; margin:-3px 0 11px !important;">
            <a class="fb_button fb_button_medium" href="#" onclick="fbLogin()" style="border-radius:6px 6px 6px 6px; display:inlineblock;">
                <span style="border-radius:0 6px 6px 0;  background-clip: padding-box;" class="fb_button_text">Login with Facebook</span>
            </a>
        </div>
        ...

Can anyone give me a hand, please? Thanks.


Solution

  • Your POST request parameters are wrong. Working code:

        try {
            Connection.Response response = Jsoup.connect("http://www.gpro.net/gb/Login.asp?langCode=gb&Redirect=gpro.asp")
                    .method(Connection.Method.POST)
                    .data("textLogin", "")  // username
                    .data("textPassword", "") // password
                    .data("Logon", "Login")
                    .execute();
    
            System.out.println(response.body());
            System.out.println(response.cookies());
        } catch (IOException e) {
            e.printStackTrace();
        }