[英]How to Download a file placed in a image button - HTMLUNIT
Download a file by clicking a image button.通过单击图像按钮下载文件。
I've been trying to download the files (two save icon image buttons).我一直在尝试下载文件(两个保存图标图像按钮)。 When i click the image it prompts to download zip file.
当我单击图像时,它会提示下载 zip 文件。
This is the tag as seen in page's VIEWSOURCE of buttons这是在页面按钮的VIEWSOURCE中看到的标签
<input type="image" name="ctl00$m$g_b265ad4d_cd49_41f3_a9f2_0090f0aa5504$ctl00$gvBidSetsFile$ctl02$ImageButton1" id="ctl00_m_g_b265ad4d_cd49_41f3_a9f2_0090f0aa5504_ctl00_gvBidSetsFile_ctl02_ImageButton1" title="Download" src="/SiteAssets/images/saveitem.gif" style="height:18px;width:18px;border-width:0px;">
WebClient client = new WebClient(BrowserVersion.FIREFOX_38);
HtmlPage homePage = null;
// Document doc = null;
String base="https://bidset.nycsca.org/SitePages/Obtain%20Solicitation.aspx?SN=16-15323D-1&ReqType=Solicitation&IsDlg=1&IsDlg=1";
try {
client.getOptions().setUseInsecureSSL(true);
client.setAjaxController(new NicelyResynchronizingAjaxController());
client.waitForBackgroundJavaScript(1000);
client.waitForBackgroundJavaScriptStartingBefore(1000);
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
client.getOptions().setThrowExceptionOnScriptError(false);
homePage = client.getPage(base);
synchronized (homePage) {
homePage.wait(5000);
}
System.out.println("file Page : " + homePage.getUrl());
// Document dd = Jsoup.parse(homePage.asXml());
HtmlInput docs= homePage.getFirstByXPath("//input[@id='ctl00_m_g_b265ad4d_cd49_41f3_a9f2_0090f0aa5504_ctl00_gvBidSetsFile_ctl02_ImageButton1']");
homePage = bidDocs.click();
Questions: As I get问题:当我得到
HtmlInput docs = homePage.getFirstByXPath
("//input[@id='ctl00_m_g_b265ad4d_cd49_41f3_a9f2_0090f0aa5504_ctl00_gvBidSetsFile_ctl02_ImageButton1']");
Is it ok to perform,表演可以吗,
homePage = bidDocs.click();
here clicking on the save icon downloads file.在这里单击保存图标下载文件。
I m confused how could I download this file with help of HTMLUNIT .我很困惑如何在 HTMLUNIT 的帮助下下载此文件。 I want to download file in my local drive .
我想下载本地驱动器中的文件。
Is it possible to get url link of homepage after (homePage = bidDocs.click();)是否可以在 (homePage = bidDocs.click();) 之后获取主页的 url 链接
ie store link , String docurl=get homePage's link . ????
即 store link ,
String docurl=get homePage's link . ????
String docurl=get homePage's link . ????
If i could get the link I can use BufferedStream
to download file .如果我能得到链接,我可以使用
BufferedStream
下载文件。
File file = new File("C:/TRY/file/abc.zip"); BufferedInputStream in = null; FileOutputStream fout = null; try { in = new BufferedInputStream(new URL(docUrl).openStream()); fout = new FileOutputStream(file); final byte data[] = new byte[1024]; int count; while ((count = in.read(data, 0, 1024)) != -1) { fout.write(data, 0, count); } } finally { if (in != null) { in.close(); } if (fout != null) { fout.close(); } }
I've to use HTMLUNIT
here because it is javascript
, iframe
site.我必须在这里使用
HTMLUNIT
,因为它是javascript
、 iframe
站点。 Im thankful for you help.我很感谢你的帮助。
Thank you verymuch.非常感谢。
Selecting the file tag选择文件标签
HtmlInput download = pageCheck.getByXPath("//input[@title='Download']");
and for streamming和流媒体
download.click().getWebResponse().getContentAsStream()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.