Java 使用htmlUnit登录学校网站
我正在尝试为我的学校网站(reggienet.illinoistate.edu)制作一个应用程序,但我无法输入登录名并将其存储在我登录的cookies中。我在网上搜遍了所有我能找到的东西,但是什么都没用,我完全迷路了 这是我现在掌握的代码Java 使用htmlUnit登录学校网站,java,html,Java,Html,我正在尝试为我的学校网站(reggienet.illinoistate.edu)制作一个应用程序,但我无法输入登录名并将其存储在我登录的cookies中。我在网上搜遍了所有我能找到的东西,但是什么都没用,我完全迷路了 这是我现在掌握的代码 public void login() { HtmlPage currentPage = null; Scanner keyboard = new Scanner(System.in); WebClient webClient = ne
public void login()
{
HtmlPage currentPage = null;
Scanner keyboard = new Scanner(System.in);
WebClient webClient = new WebClient();
try
{
webClient = reggieLogin(webClient, keyboard);
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
currentPage = webClient.getPage(""https://reggienet.illinoisstate.edu/portal"");
}
catch (FailingHttpStatusCodeException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
String pageSource = currentPage.asXml();
System.out.print(pageSource);
}
private WebClient reggieLogin(WebClient webClient, Scanner keyboard) throws Exception
{
webClient.getOptions().setJavaScriptEnabled(false);
HtmlPage currentPage = webClient.getPage("https://account.illinoisstate.edu/centrallogin/"); //Load page at the STRING address.
HtmlInput username = currentPage.getElementByName("username"); //Find element called loginuser for username
System.out.print("ULID: ");
username.setValueAttribute(keyboard.nextLine()); //Set value for username
HtmlInput password = currentPage.getElementByName("password"); //Find element called loginpassword for password
System.out.print("Password: ");
password.setValueAttribute(keyboard.nextLine()); //Set value for password
HtmlButtonInput submitBtn = currentPage.getElementByName("submit"); //Find element called Submit to submit form.
currentPage = submitBtn.click(); //Click on the button.
return webClient;
}
有人能提供帮助吗,或者有人能看出这段代码有什么问题吗?考虑使用Selenium库与网站进行交互。它具有编辑浏览器cookie的方法 也许您需要将JavaScriptEnabled设置为true?我只是想知道,因为大多数现代网站都需要启用javascript。好吧,我试过了,但不幸的是没有成功,它仍然没有意识到我登录的是有前途的书籍,我会尝试一下!幸好这不是我想要的,因为它需要一个外部浏览器。我正在寻找一种可以在android研究中作为网络垃圾的东西哦,对不起,我从来没有做过android开发@安得烈