简体   繁体   中英

JSoup Login to Website

I am reading around StackOverflow and I can't find a fix for my code. I'm pretty sure I'm just doing some silly mistake as this is the first time using JSoup.

My main goal is logging into the website: https://ps.seattleschools.org/public/

Right now I have this code:

public static final String USERNAME = "---Place Holder---";
public static final String PASSWORD = "---Place Holder---";

public static final String URL = "https://ps.seattleschools.org/public/";
public static final String POST_URL = "https://ps.seattleschools.org/guardian/home.html";

public static void main(String[] args) throws IOException {

    Connection.Response loginForm = Jsoup.connect(URL)
            .data("Account", USERNAME)
            .data("pw", PASSWORD)
            .method(Connection.Method.POST)
            .execute();


    Document document = Jsoup.connect(POST_URL)
            .cookies(loginForm.cookies())
            .get();

    System.out.println(document);


}

If you look on the website, the form is really big, but most of the items are hidden. Am I supposed to fill them out anyway? Anyways, thanks for helping

Generally, yes , you need to include all inputs that will be sent along with your POST request.

For some reason your link is not working for me (takes too long to load). So I'll layout a set of general practices to follow when logging in with Jsoup:

  1. Sometimes it's essential to first load the login page, and save the cookies to pass on to the actual login request (some websites will send you a security token when you load the login page, this needs to be sent along with the request)

  2. Hidden inputs are there for a reason. You need to include them! One way to find out what inputs you need to send is by examining the post request sent with developer tool.

I'd suggest you read up on a blog I wrote about logging into a website using Jsoup. As long as the website does not have any fancy JavaScript to prevent you, I'm certain you will be able to login to any website by following the procedures I've written.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM