简体   繁体   English

如何将网页快照及其所有元素(css、js、图像等)保存到一个文件中

[英]How to save a web page snapshot with all its elements (css, js, images, ...) into one file

How is it possible to programmatically save a web page snapshot with all its elements (css, js, images, ...) into one file?如何以编程方式将网页快照及其所有元素(css、js、图像等)保存到一个文件中?

I need to archive some web pages regularly.我需要定期存档一些网页。 However, just saving their HTML code is useless - not only because of images missing but esp.然而,仅仅保存他们的 HTML 代码是没有用的——不仅是因为图像丢失,尤其是因为图像丢失。 because the absence of CSS on today's pages can turn a web page into unrecognizable mess.因为当今页面上缺少 CSS 可能会将网页变成无法识别的混乱。

I remember the .mht format that worked like this, but that required manual saving, and it was just a feature of IE.我记得 .mht 格式是这样工作的,但这需要手动保存,这只是 IE 的一个功能。 I believe there is an open-source solution that can achieve this programmatically, but despite hours of searching I cannot find it on the web.我相信有一个开源解决方案可以以编程方式实现这一点,但尽管搜索了数小时,我还是无法在网络上找到它。

Use wget in terminal在终端中使用 wget

wget -p -k http://www.example.com/

It'll make a clone of site frontend html, css, js, svg etc. But not in one file as asked.它将克隆站点前端的 html、css、js、svg 等。但不是按要求在一个文件中。 Rather, it'll recreate the whole folder structure相反,它会重新创建整个文件夹结构

Eg if folder structure of www.example.com is as例如,如果www.example.com文件夹结构是

 /css/*
 /js/*
 /index.html

then it'll create the same structure locally.然后它会在本地创建相同的结构。

Docs: https://www.gnu.org/software/wget/manual/wget.html文档: https : //www.gnu.org/software/wget/manual/wget.html

I think @reisio (+1) has you covered...我认为@reisio (+1) 已经涵盖了您...

...But if only to plug a great free tool, I would point out the Firefox extension Save Complete , which does an admirable job of grabbing "complete" pages on an ad hoc basis. ...但如果只是为了插入一个很棒的免费工具,我会指出 Firefox 扩展Save Complete ,它在临时抓取“完整”页面方面做得非常出色。 The output will be a single HTML file with an accompanying directory stuffed with all the resources - you can easily zip them up for archiving.输出将是一个单独的 HTML 文件,附带一个包含所有资源的目录 - 您可以轻松地将它们压缩以进行存档。

It's not without fault - I've had issues with corrupted .png files lately on OSX, but I use it frequently for building mockups off of live pages and it's a huge time-saver.这并非没有错——我最近在 OSX 上遇到了损坏的.png文件的问题,但我经常使用它来从实时页面构建模型,这是一个巨大的节省时间。 (Also of note, it hasn't been updated for FF 4 yet, and is the sole reason I rolled back to 3.6) (另外请注意,FF 4 还没有更新,这是我回滚到 3.6 的唯一原因)

Apple's Safari has a pretty good solution. Apple 的 Safari 有一个很好的解决方案。 It saves all HTML and CSS (sadly no JS) but in a format called webarchive.它保存了所有 HTML 和 CSS(遗憾的是没有 JS),但是以一种称为 webarchive 的格式保存。 It's one file, but it requires Safari to save and open, and Safari requires a Mac.它是一个文件,但它需要 Safari 来保存和打开,而 Safari 需要一台 Mac。 Even though Safari for Windows does exist , it's too old to work with webpages, and it doesn't even support saving as webarchive, or opening them.尽管 Safari for Windows确实存在,但它太旧而无法处理网页,它甚至不支持另存为 webarchive 或打开它们。 If you have a Mac, open any website in Safari and press ⌘S and then make sure that Web Archive appears in the drop down.如果您使用的是 Mac,请在 Safari 中打开任何网站并按 ⌘S,然后确保 Web Archive 出现在下拉列表中。

There is also a Chrome extension that can open these types of files, but not save them.还有一个Chrome 扩展程序可以打开这些类型的文件,但不能保存它们。

Apologies for replying to such an old thread, just wanted to spread this info!抱歉回复这么旧的帖子,只是想传播这个信息!

If you are using Google Chrome just use the save page as menu entry (CTRL + s), and select complete website from the options at the bottom of the file dialog.如果您使用的是 Google Chrome,只需将保存页面用作菜单项 (CTRL + s),然后从文件对话框底部的选项中选择完整的网站。 This save the HTML and all required resources (in a separate folder).这将保存 HTML 和所有必需的资源(在单独的文件夹中)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将所有资源(css、js、图像)嵌入到一个 html 文件中? - How to embedded all resources(css,js,images) into one single html file? 每当我在Vim中保存其“源文件”时,如何自动更新或压缩CSS,JS和HTML文件? - How to automatically update or compress a CSS, JS and HTML file every time I save its “source file” in Vim? 如何从一个HTML文件加载所有CSS和JS? - How to load all CSS and JS from one html file? JS:隐藏除了一个(由id)以及它的所有降序子元素及其父元素之外的所有元素 - JS: Hide all elements except of one (by id) (and all of its descending child elements and its parents) JS重定向到另一页并将类附加到其元素之一 - JS redirecting to another page and appending class to one of its elements 如何更改页面中所有元素的CSS-JavaScript - How to change the CSS of all the elements in the page - JavaScript 如何使用js在网页中提取所有当前视频文件及其地址? - How to extract all the current video files and its address in the web page with js? 如何使用nodejs获取网站上所有图像/ css / js的所有文件大小? - How can I get all the file sizes of all the images/css/js on my website using nodejs? 你能把 css 和 js 放在一个缩小的文件中,然后在 web 页面上使用它吗? - Can you put css and js in one minified file and use it on a web page? 如何使用WGET以所有内容(js,图像,css等)将HTML格式的CGI页面下载为html? - How to download CGI page as a html with all the stuff (js, images, css and etc) using WGET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM