78

Often I need to download a webpage and then edit it offline. I have tried a few tools and the main feature they lack is downloading images referenced in the CSS files.

Is there a tool (for Linux) that will download everything so that the webpage will render the same offline (excluding AJAX)?

3
  • 3
    This worked for me the best:::::::::::: wget --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --no-parent example.com
    – Rehmat
    May 6, 2016 at 5:50
  • --html-extension is deprecated as of v1.12. I recommend this: wget -U "Opera 11.0" --page-requisites --content-on-error --no-clobber --convert-links --restrict-file-names=windows --no-parent "http://stackoverflow.com" It's very important to put url in double quotes, otherwise, it will get stuck on Redirecting output to ‘wget-log’..
    – Shayan
    Sep 4, 2019 at 17:35

7 Answers 7

97
wget --page-requisites http://example.com/your/page.html

This option causes Wget to download all the files that are necessary to properly display a given html page. This includes such things as inlined images, sounds, and referenced stylesheets.

EDIT: meder is right: stock wget does not parse and download css images. There is, however, a patch that adds this feature: [1, 2]

UPDATE: The patch mentioned above has been merged into wget 1.12, released 22-Sep-2009:

** Added support for CSS. This includes:
 - Parsing links from CSS files, and from CSS content found in HTML
   style tags and attributes.
 - Supporting conversion of links found within CSS content, when
   --convert-links is specified.
 - Ensuring that CSS files end in the ".css" filename extension,
   when --convert-links is specified.
10
  • 7
    As far as I know, this won't download images referenced in CSS files, which is what the OP intended. I think you would have to write a script that parses the css files, or find one someone's made, I'm curious about this too though. Oct 17, 2009 at 6:35
  • You should download the whole directory images recursively
    – OscarRyz
    Oct 17, 2009 at 8:19
  • seems that patch has been around since 07, and still not integrated...
    – hoju
    Oct 18, 2009 at 23:17
  • 3
    It seems wget 1.13.4 still has trouble finding CSS files linked by using the @import syntax.
    – Flimm
    Sep 22, 2012 at 10:33
  • 1
    @Shayan No - curl can NOT download whole web pages, because it cannot parse HTML: ec.haxx.se/usingcurl-downloads.html#client-differences
    – ax.
    Sep 4, 2019 at 12:35
12

I ran into the same problem the other day working for a client. Another tool that works really well is HTTrack. The software is available in a commandline verison for both windows and Linux. For Linux they prebuilt packages for most of the more common operating systems found here

For my purposes it worked better than wget with some of the added features/switches that fix links inside the html file.

3
  • What syntax do you use for this task?
    – Joe Mornin
    Jun 17, 2013 at 17:48
  • Pretty complete documentation is here link I dont remember the exact settings I used, but I tried a couple different combinations to pull down what I needed. Jun 19, 2013 at 17:48
  • @EveretteMills that what i was looking for thanks Sep 16, 2016 at 12:07
12

It's possible to do this through Firefox, see this form

  1. Right click
  2. View page info
  3. Select media tab
  4. Highlight all files
  5. Save as

Reference - http://www.webdeveloper.com/forum/showthread.php?t=212610

6
  • 10
    This does not help when it comes to saving css or js files
    – LiveSource
    Jan 8, 2013 at 10:27
  • 4
    doesn't get CSS, which was specified by the Op. It's a cool trick/process though. Would not have thought of it myself. Thanks for posting.
    – BishopZ
    May 1, 2013 at 18:54
  • 1
    It worked for me, saved all the PNGs used via css, great thanks. Jul 25, 2013 at 9:09
  • 3
    It does download images referenced in CSS files. So if it's only about images and other media, this will do.
    – SPRBRN
    Nov 1, 2013 at 11:51
  • This worked great for me, and did not require me to grab any new tools.
    – Dan
    Jun 5, 2014 at 18:50
8

wget is a great choice for you. Just for more information, the wget version on windows at this time there is no official release on gnu for wget version 1.12. The current version is 1.11

wget version 1.11 cannot download images/fonts in css files. Fortunately, you can find a build of 1.14 from this page. It fixed these problems.

http://opensourcepack.blogspot.com/2010/05/wget-112-for-windows.html

1
  • 3
    +1 for letting us know there was no windows version 1.12 Sep 24, 2012 at 0:35
4

The current version of Opera (12) allows to save a page as 'HTML with images'.

Thereby Opera also downloads images which are referenced in the CSS files and adapts the image URLs in the CSS accordingly.

3
  • Worked perfectly where other options failed. Sep 18, 2013 at 19:55
  • @Marco Do I just use the "right click -> Save as..." option as usual?
    – Shayan
    Sep 4, 2019 at 17:17
  • There's a significant difference between saving with Chrome and Opera, Chrome html file and folder of my saved webpage is about 2MB and Opera's about 3MB.
    – Shayan
    Sep 4, 2019 at 17:21
2

In Firefox:

File->Save Page As->Web Page, Complete

Saves all javascript and images and css. Nothing else required :)

1
  • 8
    Unfortunately, this method won't download images referenced within CSS files (in currently latest FF 21 and lower).
    – sgnsajgon
    Jun 17, 2013 at 22:32
-9
wget 

Not the answer you're looking for? Browse other questions tagged or ask your own question.