0

I want to simulate a login and then scrape some content while maintaining the logged-in session. I've got it working using HtmlUnit, but was looking into Jsoup since I want it to work on Android as well.

loginUrl = https://www.internetvas.slt.lk/SLTVasPortal-war/login/j_security_check

usageUrl = https://www.internetvas.slt.lk/SLTVasPortal-war/application/index.jsp?page=usage ; this is the page that I need extract information from.

[UPDATE -- ]

Thanks to greenapps, I've finally been able to login successfully. Just had to change the loginUrl, from ../login/login.jsp to ../login/j_security_check

Here's the working code:

Connection.Response response = Jsoup.connect(loginUrl)
                                  .data("j_username", myUserName)
                                  .data("j_password", myPassword)
                                  .method(Method.POST).execute();

Document usageDoc = Jsoup.connect(usageUrl).cookies(response.cookies()).get();

System.out.print(usageDoc.toString());

But now the problem is, once logged in, some content that are generated through JS are shown blank or empty. Is there a workaround to get those values show up?

Community
  • 1
  • 1
Gayan Weerakutti
  • 11,904
  • 2
  • 71
  • 68

1 Answers1

1

Your loginUrl should be https://www.internetvas.slt.lk/SLTVasPortal-war/login/j_security_check1. As you can see in <form id="login_form" action="j_security_check" method="post">.

greenapps
  • 11,154
  • 2
  • 16
  • 19