使用jsoup登录网站 [英] Login on website using jsoup
问题描述
在此网站上,您可以输入学生证号码,然后显示多少钱留在那张卡上.我想使用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. 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()
还是.get()
? - 在使用chrome devoloper工具时,发布数据是我使用
.data(.., ..)
函数发送的所有数据.但是,如果发送__VIEWSTATE
我收到错误消息,为什么? - 我应该发送解密或加密的数据吗? (均在chrome devoloper工具中提供).
- 使用正确的URL吗?
- Should I use
.post()
or.get()
? - When looking in chrome devoloper tools, the post data is all the data I send with
.data(.., ..)
function. However if a send__VIEWSTATE
I get an error, why? - Should I send decrypted or crypted data? (both are presented in chrome devoloper tools).
- Am using the correct URL?
推荐答案
您应同时使用get
和post
:
首先,您必须将不带参数的get
请求发送到URL
- http://kortladdning3. chalmerskonferens.se/Default.aspx .服务器回复一些cookie,以及稍后将使用的两个值-__VIEWSTATE
和__EVENTVALIDATION
.这些值因请求而异,因此您不能像以前那样使用硬编码的值.
提取这些值后,发送post
请求,并使用与现在相同的字段.
您可以在此处查看非常相似的过程-提交登录问题Jsoup的表单
You should use both get
and post
:
First you have to send get
request with no parameters to the URL
- http://kortladdning3.chalmerskonferens.se/Default.aspx. The server replies with some cookies, and two values you'll use later - __VIEWSTATE
and __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.
You can look at a very similar procedure here - Problems submitting a login form with Jsoup
这篇关于使用jsoup登录网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!