External Libraries

Jsoup login to website using post method example

Jsoup login to website using post method example shows how to login to a website by posting all parameters using Jsoup. Example also shows how to manage cookies while log in to website.

How to login to website using Jsoup using POST method?

Step 1:

Have a look at how to post form data using Jsoup example.

Step 2:

Open the website login page in your browser which supports inspecting the HTML elements to make things easier. For this example, we are going to login to http://www.rediff.com.

We need to inspect the login form so that we can determine
1) All required form parameters.
2) Where login form data needs to be submitted.

Here is the login form.

_jsoup_login1

We need to determine the action URL and form data fields. Right click on the login Id text field and select inspect menu item as given in the screenshot.

_jsoup_login2

It will open the developer tools with elements tab opened in the lower half of the browser. Tools will also have login id input element selected in the source. Now, locate the parent form element of the login id input element.

_jsoup_login3

This is the form we are interested in. URL mentioned in the “action” attribute of the form is where we need to post the data. We also need to send all inputs (including hidden), textarea and select elements contained in the form along with name and values as parameters in the POST method. Make a note of all the parameter name and values.

Once the parameters and action URL is determined, we can go ahead and login to the website using Jsoup as given below.

Output

Disclaimer: The URLs given/accessed in the example are purely for demonstration purpose. You should not access any URLs in any way which is not permitted by website’s terms of service agreement.

Please let us know your views in the comments section below.

 

Tags
Join 1000+ fellow learners! Enter your email address below: