2016-03-31 15 views
0

学校のウェブサイト(reggienet.illinoisstate.edu)用のアプリケーションを作成しようとしていますが、ログインを入力して自分のCookieに保存することに問題があります私はウェブを精査して見つけたものすべてを試しましたが、何も動いていません。私は完全に失われています。ここでhtmlUnitを使用して学校のウェブサイトにログインする

は、私が今持っているコード

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; 
} 

誰もが任意のヘルプを提供することができますがある、または誰もがこのコードで間違っているものを見ることができますか?

+0

おそらくJavaScriptEnabledをtrueに設定する必要がありますか?現代のほとんどのウェブサイトでJavaScriptが有効になっている必要があるため、不思議に思っています。 –

+0

さて、私はそれを試みたが、残念ながらそれは動作しませんでした、それはまだ私がログインしていることを認識しません – Andrew

答えて

0

Seleniumライブラリを使用してWebサイトとやりとりすることを検討してください。ブラウザのクッキーを編集する方法があります。 Here is a link to its java documentation.

+0

有望見える、私はそれを試してみましょう!ありがとう – Andrew

+0

問題ありません! @Andrew – Bautista

+0

残念ながら、これは外部のブラウザが必要なので、私が探していたものではありませんでした。私はアンドロイドスタジオでwebscraperとして動作するものを探しています – Andrew

関連する問題