如何用Java下载一个完整的网页(及其所有内容)?

发布于 2024-08-18 23:13:55 字数 110 浏览 2 评论 0原文

使用 Java,我需要保存一个完整的网页(及其所有内容,如图像、css、javascript 等),就像我们如何使用 HttpClient lib 的“另存为”-->“完整网页”选项一样。我该怎么做?

Using Java, I need to save a complete webpage(with all its contents like images, css, javascript e.t.c) like how we can do with save as-->complete webpage option with HttpClient lib. How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

过期以后 2024-08-25 23:13:55

你可以尝试 libcurl java
http://curl.haxx.se/libcurl/java/

你也可以参考这个讨论
curl-equivalent-in-java

You can try lib curl java
http://curl.haxx.se/libcurl/java/

And you can refer to this discussion also
curl-equivalent-in-java

菩提树下叶撕阳。 2024-08-25 23:13:55

您必须编写一个应用程序来获取 html 文件,对其进行解析并提取所有引用,然后获取通过解析找到的所有文件。

You have to write an application that fetches the html file, parses it and extracts all the references, and then fetches all the files found by parsing.

南风起 2024-08-25 23:13:55

这并不容易,因为一些 CSS/JS/Images 文件路径可能是“隐藏的”。只需考虑以下示例:

<script type="...">
   document.write("&bla;script" + " type='...' src='" + blahBlah() + "'&bla;" + "&bla;/script&bla;");
</script>

但是,获取页面源代码、在搜索 URL 时进行解析以及下载已建立的 URL 几乎是您可能需要的一切。

It's not so easy because some CSS/JS/Images files paths might be "hidden". Just consider the following example:

<script type="...">
   document.write("&bla;script" + " type='...' src='" + blahBlah() + "'&bla;" + "&bla;/script&bla;");
</script>

However, fetching page source, parsing in the search for URLs and downloading founded URLs is pretty everything you'll probably need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文