1

htmlunitこんにちは、サーバーへのログインに使用しようとしています。JavaScript サポートを無効にするとhtmlunit's、プログラムはログイン情報の投稿に成功しますが、「JavaScript を使用していないため、続行を 1 回押す必要があります」という別のページにリダイレクトされます。この続行ボタンのクリックを自動化すると、通常のブラウザーでも 404 ページが表示されるため、これはオプションではありません。

そのため、認証を実行するには JavaScript をセットアップする必要があります。誰かがこれで私を助けてくれますか? 以下は、私のコード、スローされたエラーのスタック トレース、および作業中の html ソースです。前もって感謝します。

    WebClient wc = new WebClient(BrowserVersion.FIREFOX_3_6);
    wc.getCookieManager().setCookiesEnabled(true);
    wc.setJavaScriptEnabled(true);

    HtmlPage page0 = wc.getPage("https://my.usc.edu/wp/shiblogin.do?r=/wp/student/searchForm.do");
    HtmlPage page1 = wc.getPage("https://shibboleth.usc.edu/idp/Authn/UserPassword");

    HtmlForm loginForm = page1.getForms().get(0);

    //HtmlSubmitInput button = loginForm.getInputByValue("Login");
    HtmlTextInput userField = loginForm.getInputByName("j_username");
    HtmlPasswordInput passwordField = loginForm.getInputByName("j_password");

    userField.setValueAttribute("username");
    passwordField.setValueAttribute("password");

    HtmlPage page2 = (HtmlPage) loginForm.getInputByValue("Login").click();

    String htmlBody = page2.getWebResponse().getContentAsString();

    System.out.println(page2.asText());
    System.out.println(htmlBody);

Caused by: com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 >/wp/student/searchForm.do/index.html for >https://my.usc.edu/wp/student/searchForm.do/index.html
>   at >com.gargoylesoftware.htmlunit.WebClient.throwFailingHttpStatusCodeExceptionIfNecessary(WebCli>ent.java:543)
>   at com.gargoylesoftware.htmlunit.WebClient.download(WebClient.java:2228)
>   at >com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFormElement.submit(HTMLFormElement.jav>a:310)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>   at >sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>   at java.lang.reflect.Method.invoke(Method.java:597)
>   at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:137)
>   ... 34 more
>== CALLING JAVASCRIPT ==
>function () {
>   [native code, arity=0]
>}

>======= EXCEPTION END ========

<form id="loginform" action="/idp/Authn/UserPassword" method="post" onsubmit="if (this.getAttribute('submitted')) return false; this.setAttribute('submitted','true'); document.getElementById('submit').disabled=true;" >

                <fieldset>
                    <legend>USCnet Login</legend>
                    <table id="login">
                        <tr>
                            <th><label for="j_username">USC NetID:</label></th>
                            <td><input id="j_username" name="j_username" type="text" maxlength="12" value="" /></td>
                        </tr>
                        <tr>
                            <th><label for="j_password">Password:</label></th>
                            <td><input id="j_password" name="j_password" type="password" /></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><input id="submit" type="submit" value="Login" /></td>
                        </tr>
4

0 に答える 0