问题
I am trying to download file via HTMLUnit. But every time when I use code like this:
InputStream stream = anchor.click().getWebResponse().getContentAsStream();
i get website instead file.
Download link looks like this:
<a id="j_id272:exportToExcel" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.forms['j_id272'],'j_id272:exportToExcel,j_id272:exportToExcel','');}return false" href="#">
<img id="j_id272:exportToExcelImage" alt="???exportToExcel???" src="/ECRM/gfx/icon_excel.gif">
</a>
Is there any way to download this?
回答1:
Page page = anchor.click();
BinaryPage bp = new BinaryPage(page.getWebResponse(),page.getEnclosingWindow());
InputStream input = bp.getInputStream();
What is inside your page? Maybe it is a 40X or other 50X error page?
回答2:
If you want get page see below:
final HtmlPage enclosedPage = (HtmlPage) anchor.click().getEnclosingWindow().getEnclosedPage();
来源:https://stackoverflow.com/questions/25136439/htmlunit-download-file