[英]How to login to Twitter using htmlunit in Java?
I am trying to login to Twitter using Java's htmlunit packages. 我正在尝试使用Java的htmlunit软件包登录Twitter。 But I get the error: com.gargoylesoftware.htmlunit.html.HtmlPasswordInput cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlTextInput
但是我得到了错误:com.gargoylesoftware.htmlunit.html.HtmlPasswordInput无法转换为com.gargoylesoftware.htmlunit.html.HtmlTextInput
WebClient webClient = new WebClient(BrowserVersion.CHROME);
HtmlPage page = webClient.getPage("https://www.twitter.com/");
HtmlForm form = page.getForms().get(1);
form.reset();
HtmlTextInput username = form.getInputByName("session[password]");
username.setText("xxxxxxx");
HtmlPasswordInput password = form.getInputByName("session[password]");
password.setText("xxxxxxx");
HtmlInput button = form.getInputByValue("Log in");
webClient.getOptions().setThrowExceptionOnScriptError(false);
HtmlPage p = button.click();
The following line in your code causes the problem 您代码中的以下行会导致问题
HtmlTextInput username = form.getInputByName("session[password]");
It should be 它应该是
HtmlTextInput username = form.getInputByName("session[username_or_email]");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.