链接中的HtmlUnit和JavaScript [英] HtmlUnit and JavaScript in links

查看:117
本文介绍了链接中的HtmlUnit和JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这里复制

我需要使用 HtmlUnit 从网站保存文件。我目前正在导航到有几个使用javascript的锚点的页面:

I need to save files from websites using HtmlUnit. I am currently navigating to pages that have several anchors that use javascript:

 onClick()="DownloadAttachment('attachmentId')" 

到目前为止,我一直无法找到显示如何使用HtmlUnit保存文件的资源或示例。我一直在努力获得 AttachmentHandler 为此工作似乎最有可能工作,但一直没有成功。

So far though I've been unable to find resources or examples that show how to save files using HtmlUnit. I've been trying mainly to get AttachmentHandler to work for this as it seems the most likely to work, but have been unsuccessful.

如何使用AttachmentHandler来获取浏览器看到的数据流点击链接?

How do I use AttachmentHandler to get at the data stream which the browser would see if I clicked on the link?

推荐答案

这比这更简单。只需模拟click事件,然后获取 WebResponse

It's more simple than that. Just simulate the click event and then get the WebResponse:

HtmlElement anchorAttachment = (HtmlElement) pageETrackerItem.getByXPath(".../a").get(0);

InputStream is = anchorAttachment.click().getWebResponse().getContentAsStream();

这篇关于链接中的HtmlUnit和JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆