2

I've been trying to login to an aspx website using a Jsoup crawler, everything I've found so far has been with forms but this aspx website here doesn't have any forms. How do I do this?

Here's what I have so far:

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

    Connection.Response currentPage = Jsoup.connect(LOGIN_FORM_URL)
            .data("LoginName", USERNAME)
            .data("Password", PASSWORD)
            .cookies(loginForm.cookies())   
            .method(Connection.Method.POST)  
            .userAgent(USER_AGENT)  
            .execute();
    System.out.println(currentPage.parse().html());
theaxluo
  • 41
  • 2

1 Answers1

2

Upon some digging I have found the answer here.

A shorter summary is provided below:

Step 1: Go onto the page you want to log in on and use the Chrome developer console (Options>Tools>Developer Tools) and type in $("input")

Step 2: Take the name and value and add it to your previous .data

Step 3: Go to page source and find and add any additional needed data with their values

After that you should be done and it should look like this

Connection.Response currentPage = Jsoup.connect(LOGIN_FORM_URL)
            .data("LoginName", USERNAME)
            .data("Password", PASSWORD)
            .data("SubmitLogon", "true")
            .userAgent(USER_AGENT)                
            .data("input[name=__VIEWSTATE]","/wEPDwULLTE5NTUyNzc3NDhkZC7w9zeYDbAWpWTaWlQFzEFw15ln")
            .data("input[name=__VIEWSTATEGENERATOR]","5A2128B1")
            .cookies(loginForm.cookies())   
            .method(Connection.Method.POST)
            .execute();
theaxluo
  • 41
  • 2