且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Jsoup登录页面

更新时间:2023-12-01 15:43:58

是的,此代码看起来像您的代码.

Yes, this code will look like yours.

Connection.Response loginForm = Jsoup.connect("https://parentviewer.pisd.edu/")
        .method(Connection.Method.GET)
        .execute();

Document document = Jsoup.connect("https://parentviewer.pisd.edu/")
        .data("ctl00$ContentPlaceHolder1$portalLogin$UserName", "testUser")
        .data("ctl00$ContentPlaceHolder1$portalLogin$Password", "testPass")
        .cookies(loginForm.cookies())
        .post();

System.out.println(document.body().html());

如何使其正常工作?***的方法是在浏览器中启用 Web开发人员控制台并登录此页面.完成此检查后,从浏览器发送到服务器的内容将发送给Jsoup,并通过JSoup发送.

How to make this working? Best way is to enable Web Developer Console in your browser and login this page. After this check what is sended from broswer to server and send this data with JSoup.

在您的示例中,请求数据如下所示:

In your example request data look like this:

Request URL:https://parentviewer.pisd.edu/
Request Method:POST
Status Code:200 OK

FormData:
__LASTFOCUS:
__EVENTTARGET:
__EVENTARGUMENT:
__VIEWSTATE:/wEPDwULLTEwNjY5NzA4NTBkZMM/uYdqyffE27bFnREF10B/RqD4
__SCROLLPOSITIONX:0
__SCROLLPOSITIONY:106
__EVENTVALIDATION:/wEdAASCW34hepkNwIXSnvGxEUTlqcZt0XO7QUOibAd3ocrpayqHxD2e5zCnWBj9+m7TCi0S+C76MEjhL0ie/PsBbOp+Shjkt2W533uAqvBQcWZNXoh672M=
ctl00$ContentPlaceHolder1$portalLogin$UserName:testUser@gmail.com
ctl00$ContentPlaceHolder1$portalLogin$Password:testPass
ctl00$ContentPlaceHolder1$portalLogin$LoginButton:Login

并非所有数据都是必需的,请以最少的请求尝试,然后检查是否可行.

Not all data are required, try with minimal request and check if this works.