问题
I don't understand what the problem is with this code (ignore the socks proxy btw that's not the issue...) I'm trying to login to my vBulletin form so I can make a script which auto bans people and stuff. But when I run this it can't even find the login form, so I wrote a for loop to list all of the forms on the main page... It only managed to find the shout box, which is not what I want! Anyone have any idea of why it can't find the login form at the top of the page?
public Application() {
System.setProperty("socksProxyHost", "localhost");
System.setProperty("socksProxyPort", "9050");
final WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setCssEnabled(false);
HtmlPage page;
try {
page = webClient.getPage("http://cartoonamon.com/forum.php");
HtmlForm login = null;
for (HtmlForm f : page.getForms()) {
System.out.println(f.getNameAttribute());
}
// HtmlTextInput username = login.getElementById("navbar_username");
// HtmlTextInput password = login.getElementById("navbar_password");
// HtmlSubmitInput submit = login.getInputByValue("Log in");
// username.setValueAttribute("nolooking");
// password.setValueAttribute("nolooking!");
// HtmlPage page2 = submit.click();
} catch (FailingHttpStatusCodeException | IOException e) {
e.printStackTrace();
}
webClient.closeAllWindows();
}
来源:https://stackoverflow.com/questions/17957622/login-to-vbulletin-using-htmlunit