简体   繁体   English

如何使用 Jsoup 登录 ASPX 网站

[英]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.我一直在尝试使用 Jsoup 爬虫登录一个 aspx 网站,到目前为止我发现的所有内容都是带有表单的,但是这里的这个 aspx 网站没有任何表单。 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")第 1 步:进入您要登录的页面并使用 Chrome 开发者控制台(选项>工具>开发者工具)并输入 $("input")

Step 2: Take the name and value and add it to your previous .data第 2 步:获取名称和值并将其添加到您之前的 .data

Step 3: Go to page source and find and add any additional needed data with their values第 3 步:转到页面源并查找并添加任何其他需要的数据及其值

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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