简体   繁体   中英

How Do You Login To An ASPX Website Using A Jsoup

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());

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();

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