1

HtmlUnit を使い始めたばかりで、Javascript を使用する sHttp ページにログインしたいのですが、問題はありますか? いいえ、ログインできません。どこに問題がありますか? 少なくとも、ログインに失敗した場合は警告が表示されるはずですが、ログインしようとしていないように見えます。すべてのアイデアに感謝します!

WebClient webClient = new WebClient();
//webClient.setJavaScriptEnabled(true);
//webClient.getCookieManager().setCookiesEnabled(true);


// Get the first page
HtmlPage page1 = (HtmlPage) webClient.getPage("http://goo.gl/AxhP8");
HtmlPage page2 = (HtmlPage) page1.getFrameByName("text").getEnclosedPage();

// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
HtmlForm form = page2.getFormByName("login");

// Enter login and passwd
form.getInputByName("xlogin").setValueAttribute("login");
form.getInputByName("xpasswd").setValueAttribute("password");


// Click "Sign In" button/link
page1 = (HtmlPage) form.getInputByValue("Přihlásit").click();

//  Get page as Html
String htmlBody = page1.getWebResponse().getContentAsString();
//  Save the response in a file
String filePath = "test_out.html";

BufferedWriter bw = new BufferedWriter(new FileWriter(new File(filePath)));
bw.write(htmlBody);
bw.close();

webClient.closeAllWindows();

フォームは次のとおりです (または、ここでソースを取得できます: http://goo.gl/AxhP8 )

<form action="/fcgi/verso.fpl" method="GET" name="login" onsubmit="wipRet=true;wipRet=true;wipRet=kontrola_hesla(this);if(wipRet==false){wipRet=false;}else{vrGetScrollTop(this);doWkinPrgs(this.target,'Probíhá přihlášení uživatele ...');};if(wipRet==false){return false;}else{vrGetScrollTop(this);doWkinPrgs(this.target,'');}" target="text">
<input name="_vr_sclt" type="hidden" value="0" />
<input name="_vr_sclt" type="hidden" value="0" />
<input id="fname" name="fname" type="hidden" value="neni_js" />

Uživatel: <input class="login_in"  name="xlogin" size="15" type="text" />
Heslo: <input class="login_in" name="xpasswd" size="15" type="Password" />
<input class="btn" type="submit" value="Přihlásit" width="50" />

<input name="__formid" type="hidden" value="2a620f43d0478d14" />
<input name="__idf" type="hidden" value="afc09868294ba6ac" />
<input name="__formid" type="hidden" value="f73fa3ddfe457bc1" />
<input name="__idf" type="hidden" value="3162299a379cf323" />

</form>

少し助けてくれてありがとう、私は数時間を費やし、多くの記事を読みましたが、先に進むことができません、thx :) クッキーなどに問題はありますか?

4

1 に答える 1

0
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);

Firefox は IE よりはるかに優れている ... : // 動作するようになった

于 2012-12-02T13:40:20.680 に答える