Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

I need to archive some web pages regularly. However, just saving their HTML code is useless - not only because of images missing but esp. because the absence of CSS on today's pages can turn a web page into unrecognizable mess.

I remember the .mht format that worked like this, but that required manual saving, and it was just a feature of 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.

like image 383
Vacilando Avatar asked Apr 11 '11 20:04

Vacilando


People also ask

How do I save HTML and CSS files together?

Choose “Save As…” from the File menu, make sure that you are in the same directory/folder as the mypage. html file, and save the style sheet as “mystyle. css”. Now go back to the window with the HTML code.

How do I save a webpage with CSS?

Open up the webpage and click File-> Save Page As... and from that prompt select "Web Page, Complete" . Once you've saved this page this downloads a complete version of the html, javascript, css files and images that are referenced in the HTML.

Which HTML tag is used to create sections of content to be formatted with style sheets?

The <style> HTML element contains style information for a document, or part of a document. It contains CSS, which is applied to the contents of the document containing the <style> element. The <title> HTML element defines the document's title that is shown in a Browser's title bar or a page's tab.


2 Answers

HTTrack, -%M

like image 59
reisio Avatar answered Oct 07 '22 20:10

reisio


Use wget in terminal

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. Rather, it'll recreate the whole folder structure

E.g. if folder structure of www.example.com is as

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

then it'll create the same structure locally.

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

like image 36
Zain Khalid Avatar answered Oct 07 '22 21:10

Zain Khalid