Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t通过HtmlUnit/Java登录_Java_Htmlunit - Fatal编程技术网

Can';t通过HtmlUnit/Java登录

Can';t通过HtmlUnit/Java登录,java,htmlunit,Java,Htmlunit,我刚开始使用HtmlUnit,我想登录到一个使用Javascript的sHttp页面,这有问题吗?我希望没有,但我无法登录,问题出在哪里?至少我应该得到登录失败的警告,但一切似乎都没有尝试登录。谢谢你的每一个想法 WebClient webClient = new WebClient(); //webClient.setJavaScriptEnabled(true); //webClient.getCookieManager().setCookiesEnabled(true); // Get

我刚开始使用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();
这是表单(或者您可以从这里获得来源:)


Uživatel:
赫斯洛:
感谢每一个小小的帮助,我花了几个小时,读了很多文章,但我无法前进,thx:)饼干或类似的东西有问题吗

WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
Firefox比IE好得多…://现在可以用了

WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);