Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. //most of this is from https://gist.github.com/harisupriyanto/6805988
  2.  
  3. String loginUrl = "http://lionel2.kgv.edu.hk";
  4. int loginFormNum = 1;
  5. String usernameInputName = "nameinput";
  6. String passwordInputName = "passinput";
  7. String submitLoginButtonValue = "Sign In";
  8.  
  9. // create the HTMLUnit WebClient instance
  10. WebClient wclient = new WebClient();
  11.  
  12. // configure WebClient based on your desired
  13. wclient.getOptions().setPrintContentOnFailingStatusCode(false);
  14. wclient.getOptions().setCssEnabled(true);
  15. wclient.getOptions().setThrowExceptionOnFailingStatusCode(false);
  16. wclient.getOptions().setThrowExceptionOnScriptError(false);
  17.  
  18. try {
  19.  
  20. final HtmlPage loginPage = (HtmlPage)wclient.getPage(loginUrl);
  21.  
  22. final HtmlForm loginForm = loginPage.getForms().get(loginFormNum);
  23.  
  24. final HtmlTextInput txtUser = loginForm.getInputByName(usernameInputName);
  25. txtUser.setValueAttribute(username);
  26. final HtmlPasswordInput txtpass = loginForm.getInputByName(passwordInputName);
  27. txtpass.setValueAttribute(password);
  28. final HtmlSubmitInput submitLogin = loginForm.getInputByValue(submitLoginButtonValue);
  29.  
  30.  
  31. final HtmlPage returnPage = submitLogin.click();
  32.  
  33. final HtmlElement returnBody = returnPage.getBody();
  34. //if (//there is a class called "Login info, then print out the nodeValue.) {
  35.  
  36. // }
  37.  
  38. } catch(FailingHttpStatusCodeException e) {
  39. e.printStackTrace();
  40. } catch(Exception e) {
  41. e.printStackTrace();
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement