Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //most of this is from https://gist.github.com/harisupriyanto/6805988
- String loginUrl = "http://lionel2.kgv.edu.hk";
- int loginFormNum = 1;
- String usernameInputName = "nameinput";
- String passwordInputName = "passinput";
- String submitLoginButtonValue = "Sign In";
- // create the HTMLUnit WebClient instance
- WebClient wclient = new WebClient();
- // configure WebClient based on your desired
- wclient.getOptions().setPrintContentOnFailingStatusCode(false);
- wclient.getOptions().setCssEnabled(true);
- wclient.getOptions().setThrowExceptionOnFailingStatusCode(false);
- wclient.getOptions().setThrowExceptionOnScriptError(false);
- try {
- final HtmlPage loginPage = (HtmlPage)wclient.getPage(loginUrl);
- final HtmlForm loginForm = loginPage.getForms().get(loginFormNum);
- final HtmlTextInput txtUser = loginForm.getInputByName(usernameInputName);
- txtUser.setValueAttribute(username);
- final HtmlPasswordInput txtpass = loginForm.getInputByName(passwordInputName);
- txtpass.setValueAttribute(password);
- final HtmlSubmitInput submitLogin = loginForm.getInputByValue(submitLoginButtonValue);
- final HtmlPage returnPage = submitLogin.click();
- final HtmlElement returnBody = returnPage.getBody();
- //if (//there is a class called "Login info, then print out the nodeValue.) {
- // }
- } catch(FailingHttpStatusCodeException e) {
- e.printStackTrace();
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement