如何下载放置在图像按钮中的文件- HTMLUNIT
How to Download a file placed in a image button - HTMLUNIT
点击图片按钮下载文件
有这个链接
我一直在尝试下载文件(两个保存图标图像按钮)。当我点击图片时,它提示下载zip文件。
这是在页面的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();
问题:当我得到
HtmlInput docs = homePage.getFirstByXPath
("//input[@id='ctl00_m_g_b265ad4d_cd49_41f3_a9f2_0090f0aa5504_ctl00_gvBidSetsFile_ctl02_ImageButton1']");
是否可以执行,
homePage = bidDocs.click();
这里点击保存图标下载文件。
我很困惑我怎么能下载这个文件与HTMLUNIT的帮助。我想在我的本地驱动器上下载文件。
是否可以在(homepage = bidDocs.click();)
。存储链接,String docurl=get homePage's link . ????
如果我能得到链接,我可以使用
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(); } }
这里我必须用HTMLUNIT
,因为它是javascript
, iframe
站点。我很感谢你的帮助。
选择文件标签
HtmlInput download = pageCheck.getByXPath("//input[@title='Download']");
和用于流媒体的
download.click().getWebResponse().getContentAsStream()
相关文章:
- 如何使按钮图像在单击时添加到变量中
- HTML滚动按钮图像:如何使用Internet Explorer
- jquery ui按钮图像没有更改
- 如何检测长按按钮/图像
- 使用 Jquery 的单选按钮图像
- 如何在 jqgrid 中添加新的按钮/图像列
- Javascript,切换具有相同名称的单选按钮图像
- 我怎样才能使这个切换的javascript按钮(图像)不那么笨拙
- w2ui-单击时工具栏更改按钮图像
- Jquery在ajax上设置onclick null并更改按钮图像成功
- 如何更改HTML5音频中的播放/按钮图像
- 日期选择器按钮图像未显示
- jQuery是否验证冲突提交函数,而不是表单按钮(图像/超链接)
- 我需要添加一个图像数组,可以使用JavaScript更改按钮图像或数字条目
- 在firefox中创建自定义按钮(使用自定义按钮插件)不允许我调整按钮图像的大小
- 更改按钮图像onclick
- Angular JS知道什么是用复选框图像和单选按钮图像触发的
- 用按钮图像填充表单文本字段
- javascript表单提交更改提交按钮图像
- 从内联css和JavaScript点击更改按钮图像