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()
or .get()
?.data(.., ..)
function. However if a send __VIEWSTATE
I get an error, why?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
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.