且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

(如何)我可以使用JSoup下载图像?

更新时间:2023-12-03 20:57:46

在找到问题之前,我甚至没有写完问题通过JSoup回答并进行一些实验。

I didn't even finish writing the question before I found the answer via JSoup and a little experimentation.

//Open a URL Stream
Response resultImageResponse = Jsoup.connect(imageLocation).cookies(cookies)
                                        .ignoreContentType(true).execute();

// output here
FileOutputStream out = (new FileOutputStream(new java.io.File(outputFolder + name)));
out.write(resultImageResponse.bodyAsBytes());  // resultImageResponse.body() is where the image's contents are.
out.close();