[英]Login on website using jsoup
On this website , you can enter your student-card-number, and then it will display how much money is left on that card.在这个网站上,您可以输入您的学生卡号,然后它会显示该卡上还剩多少钱。 I want to obtain the information using JSOUP.
我想使用 JSOUP 获取信息。 This is my current code, but it does not work,
这是我当前的代码,但它不起作用,
String url = "http://kortladdning3.chalmerskonferens.se/CardLoad_Order.aspx";
Connection.Response loginForm = Jsoup.connect(url)
.method(Connection.Method.GET)
.execute();
Document document = Jsoup.connect(url)
.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36")
//.data("__VIEWSTATE","%2FwEPDwUHNjA4NDA1NQ9kFgQCAw9kFgoCAQ9kFgICAQ8PFgIeBFRleHQFClBUTSBLb3J0bnJkZAICDxYCHgdWaXNpYmxlaGQCAw8WAh8BaGQCBA8WAh8BaGQCBQ8WAh8BaBYCAgEPEGRkFgBkAgUPDxYCHwAFCShkZXNrdG9wKWRkZGzBhwMIv3yxqKnC0C7%2BPlC0PlDG")
.data("__EVENTVALIDATION", "%2FwEWBAKG7bXPBQLi0uqnCgKF69rWBAK14fOOCgrUt4CBVP4K0VKe0uOPxLSAu26y")
.data("hiddenIsMobile", "desktop")
.data("txtCardNumber", "3819276248xxxxxx")
.data("SavedCardNumber", "")
.data("btnNext","N%C3%A4sta")
.cookies(loginForm.cookies())
.get();
System.out.println(document.html());
I dont have much experience so I dont know where to look for the problem.我没有太多经验,所以我不知道去哪里寻找问题。 Some thoughts:
一些想法:
.post()
or .get()
?.post()
还是.get()
?.data(.., ..)
function..data(.., ..)
函数发送的所有数据。 However if a send __VIEWSTATE
I get an error, why?__VIEWSTATE
我得到一个错误,为什么?You should use both get
and post
:你应该同时使用
get
和post
:
First you have to send get
request with no parameters to the URL
- http://kortladdning3.chalmerskonferens.se/Default.aspx .首先,您必须向
URL
- http://kortladdning3.chalmerskonferens.se/Default.aspx发送不带参数的get
请求。 The server replies with some cookies, and two values you'll use later - __VIEWSTATE
and __EVENTVALIDATION
.服务器回复一些 cookie,以及您稍后将使用的两个值 -
__VIEWSTATE
和__EVENTVALIDATION
。 These values vary from request to request, so you can't use hard-coded values like you did.这些值因请求而异,因此您不能像以前那样使用硬编码值。
After extracting these values, send post
request, with the same fields you do now.提取这些值
post
,使用您现在所做的相同字段发送post
请求。
You can look at a very similar procedure here - Problems submitting a login form with Jsoup您可以在此处查看非常相似的过程 - 使用 Jsoup 提交登录表单的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.