我想从网站下载 config.bin 文件。使用htmlunit
final WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setTimeout(2000);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.setConfirmHandler(new ConfirmHandler() {
public boolean handleConfirm(Page page, String message) {
System.out.println(" -----------------------");
System.out.println("handle config");
System.out.println(" -----------------------");
return true;
}
});
final HtmlPage page = webClient.getPage("http://site");
final DomElement backup = mainFrame.getElementByName("Backup");
webClient.addWebWindowListener(new WebWindowListener()
{
public void webWindowClosed(WebWindowEvent event)
{
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1");
};
public void webWindowContentChanged(WebWindowEvent
event)
{
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2");
}
public void webWindowOpened(WebWindowEvent event)
{
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!3");
}
});
InputStream input = backup.click().getWebResponse().getContentAsStream();
然后提交ckick()
我认为获取流,但获得了提交页面。我认为我的浏览器窗口有问题,我无法处理浏览器窗口。我在处理程序中插入sout
,看看此方法何时被调用,但它没有调用
答案 0 :(得分:0)
问题出在我安装的时期。已更改setTimeout
并且全部正常工作。
webClient.getOptions().setTimeout(15000);