开发者

A question on downloading file via HtmlUnit

So here's the deal:

I am accessing some webpage(using HtmlUnit) on开发者_StackOverflow中文版 which there's a button. I programatically click that button,

When I click that button normally through the browser, I am given the chance to save a file on my hard drive. The thing is, I want to be able to get that file programatically. and save it to a specific folder, if the file size is bigger than a specific number, the downloading should be stopped, Can this be done via HtmlUnit?

Thank you so much!


In my case the file I wanted to download was a text file and below is the code I used. Hope so it gives you an idea about what is to be done.

InputStream inputStream = new HttpWebConnection(client).getResponse(req).getContentAsStream();

        StringWriter writer = new StringWriter();
        IOUtils.copy(inputStream, writer, "UTF8");
        String theString = writer.toString();

        System.out.println(theString);


Short answer... no, this cannot be done.

There is a firefox/profile base way to partially do that.

And the workaround with getPageSource() for plain text files.

Otherwise... I'm looking for similar thing. Let you know if you find a better hack...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜