如何用Java下载一个完整的网页(及其所有内容)?
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以尝试 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
您必须编写一个应用程序来获取 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.
这并不容易,因为一些 CSS/JS/Images 文件路径可能是“隐藏的”。只需考虑以下示例:
但是,获取页面源代码、在搜索 URL 时进行解析以及下载已建立的 URL 几乎是您可能需要的一切。
It's not so easy because some CSS/JS/Images files paths might be "hidden". Just consider the following example:
However, fetching page source, parsing in the search for URLs and downloading founded URLs is pretty everything you'll probably need.