5

I try to log in here: http://www.gszi.sulinet.hu/dinaweb/diakok/belepes.jsp with this:

Connection.Response loginForm = Jsoup.connect("http://www.gszi.sulinet.hu/dinaweb/diakok/belepes.jsp")
            .method(Connection.Method.GET)
            .execute();

Document doc = Jsoup.connect("http://www.gszi.sulinet.hu/dinaweb/diakok/belepes.jsp")
            .data("name","myid")
            .data("name","mycode")
            .cookies(loginForm.cookies())
            .post();

Afterwards, getting the html of a page which I have to login to see, I realize that I couldn't log in. Is there a way to login and then get the html of pages I have access now? Any link, advice or help appreciated.

Attila Toth
  • 187
  • 1
  • 2
  • 13

2 Answers2

5

You are using the same key for two different input tags. Moreover the keys you are using are wrong.

.data("jelszo","SOMETEXT")
.data("felnev","PASSWORD")

Update

Connection.Response initial = Jsoup
        .connect("http://www.gszi.sulinet.hu/dinaweb/diakok/belepes.jsp")
        .method(Connection.Method.GET).execute();

Connection.Response login = Jsoup
        .connect("http://www.gszi.sulinet.hu/dinaweb/diakok/belepes.jsp")
        .data("jelszo","SOMETEXT")
        .data("felnev","PASSWORD")
        .cookies(initial.cookies())
        .method(Method.POST)
        .execute();

Document page = Jsoup
        .connect("ANY_PAGE_INSIDE_THE_SITE")
        .cookies(login.cookies()) //use this with any page you parse. it will log you in
        .get();
Alkis Kalogeris
  • 17,044
  • 15
  • 59
  • 113
  • Yes you're rigth thank you. Now I'm not sure how I should go to another page while stay logged in? – Attila Toth Jan 25 '16 at 20:04
  • 1
    I've updated my post. Please don't forget to accept the answer if this solved your problem – Alkis Kalogeris Jan 25 '16 at 20:30
  • can you please look into https://stackoverflow.com/questions/73572751/jsoup-login-cookies-are-not-working-with-sub-pages-but-only-with-home-page, your solution is not working in my case. – vikramvi Sep 02 '22 at 10:50
1

ok, actually I have found that I need one more parameter ("akcio") and I sent post() method to the wrong URL now my program runs properly, my code:

Connection.Response loginForm = Jsoup.connect(loginFormUrl)
         .method(Connection.Method.GET)
         .execute();

    Map<String, String> loginCookies = loginForm.cookies();

    Document document = Jsoup
        .connect(loginFormUrl)
        .data("akcio", akcio)
        .data("felnev",felnev)
        .data("jelszo",jelszo)
        .cookies(loginCookies)
        .post();

    Document document2 = Jsoup.connect(loggedInUrl)
    .cookies(loginCookies)
    .get();
    System.out.println(document2);
Attila Toth
  • 187
  • 1
  • 2
  • 13