0

I have a problem: I can't login on page Betfair with Jsoup seems to be okay but do not get the return of logged page :(

// You can try with this username and password for testing
// Username: <redacted>
// Password: <redacted>
// LoginUrl: lite.betfair.com/Login.do?s=000009z-redirectDefault


// This is my Code 

Connection.Response res = Jsoup.connect("https://lite.betfair.com/SLoginsubmit.do?s=000009z-redirectDefault&secure=true")
                    .data("username", "<redacted>", "password", "<redacted>")
                    .method(Method.POST)
                    .execute();
            Map<String, String> cookies = res.cookies();


            Connection connection = Jsoup.connect("https://lite.betfair.com/Mybets.do?s=000209z");
            for (Entry<String, String> cookie : cookies.entrySet()) {
                connection.cookie(cookie.getKey(), cookie.getValue());
            }


            Document document = connection.get();
            System.out.println(document);

Who can help me?

Karlo
  • 1,630
  • 4
  • 33
  • 57
neo-_-man
  • 35
  • 7

3 Answers3

2

You have to connect to the login page and use its cookies to the post command. Something like this:

    Connection.Response response1 = Jsoup.connect("https://lite.betfair.com/Login.do?s=000009z-redirectDefault")
            .execute();
    Map<String, String> cookies = response1.cookies();

    Connection connection2 = Jsoup.connect("https://lite.betfair.com/SLoginsubmit.do?s=000009z-redirectDefault&secure=true")
               .data("username", "<redacted>")
               .data("password", "<redacted>")
               .method(Method.POST);

    for (Entry<String, String> cookie : cookies.entrySet()) {
        connection2.cookie(cookie.getKey(), cookie.getValue());
    }
    Response response2 = connection2.execute();
    cookies.putAll(response2.cookies());

    Connection connection3 = Jsoup.connect("https://lite.betfair.com/Mybets.do?s=000209z");
    for (Entry<String, String> cookie : cookies.entrySet()) {
        connection3.cookie(cookie.getKey(), cookie.getValue());
    }

    Document document = connection3.get();
    System.out.println(document);

I used your code by the way for connecting another page, and it worked the first time. So you helped me and I try to help you. :)

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
Peter Ambruzs
  • 7,763
  • 3
  • 30
  • 36
2

just you need to know what is the name of cookies or SessionName then you can use it to login

Response res = Jsoup.connect("https://lite.betfair.com/SLoginsubmit.do?s=000009z-rredirectDefault&secure=true")
                .method(Method.GET)
                .timeout(10000)
                .execute();

        sessionID = res.cookie("JSESSIONID");//her put the SessionName for website 

now you have the SessionName of website and you need to fill it

String username="your username";
String password="your pass";

Jsoup.connect("https://lite.betfair.com/SLoginsubmit.do?s=000009z-redirectDefault&secure=true")
                .data("login:username", username, "login:password", password, "login:loginImg", "", "login", "login")
                .cookie("JSESSIONID", sessionID)
                .method(Method.POST)
                .timeout(10000)
                .execute();// now you have SessionName and you can use it for any page in website


Document doc = Jsoup.connect("https://lite.betfair.com/Mybets.do?s=000209z")
                .cookie("JSESSIONID", sessionID)
                .timeout(10000)
                .get();// her to open any page with SessionName you have it

now you just need to good to tag you need it in doc to get your data from it

System.out.println(doc.body().text());
user3214337
  • 111
  • 3
0

NOTE: Session Name of website you can know it like this: Login to your website you need to know Session Name or cookies for it Then write in URL field this command after login

javascript:void(alert(document.cookie))

then get the Session name

user3214337
  • 111
  • 3