vote up 1 vote down star
2

I want to use Wget to save single web pages (not recursively, not whole sites) for reference. Much like Firefox's "Web Page, complete".

My first problem is: I can't get Wget to save background images specified in the CSS. Even if it did save the background image files I don't think --convert-links would convert the background-image URLs in the CSS file to point to the locally saved background images. Firefox has the same problem.

My second problem is: If there are images on the page I want to save that are hosted on another server (like ads) these wont be included. --span-hosts doesn't seem to solve that problem with the line below.

I'm using: wget --no-parent --timestamping --convert-links --page-requisites --no-directories --no-host-directories -erobots=off http://domain.tld/webpage.html

flag
exactly the same line ( wget --no-parent --timestamping --convert-links --page-requisites --no-directories --no-host-directories -erobots=off domain.tld ) actually saves background images referenced from CSS after updating to 1.12. The manual says: "With http urls, Wget retrieves and parses the html or css from the given url, retrieving the files the document refers to, through markup like href or src, or css uri values specified using the ‘url()’ functional notation." Second problem still needs to be solved – mikael Oct 14 at 0:23

3 Answers

vote up 1 vote down

If you had read the wget man page, you would have seen the option --mirror, which does the same thing as:

$ wget -r -N -l inf --no-remove-listing

You can also throw in -x to create a whole directory heirarchy for the site, including the hostname.

You might not have been able to find this if you aren't using the newest version of wget however, and it's also worth noting that there's a security hole that was patched recently, so it's a good idea to upgrade anyway.

link|flag
vote up 0 vote down

It sounds like wget and Firefox are not parsing the CSS for links to include those files in the download. You could work around those limitations by wget'ing what you can, and scripting the link extraction from any CSS or Javascript in the downloaded files to generate a list of files you missed. Then a second run of wget on that list of links could grab whatever was missed (use the -i flag to specify a file listing URLs).

If you like Perl, there's a CSS::Parser module on CPAN that may give you an easy means to extract links in this fashion.

Note that wget is only parsing certain html markup (href/src) and css uris (url()) to determine what page requisites to get. You might try using Firefox addons like DOM Inspector or Firebug to figure out if the 3rd-party images you aren't getting are being added through Javascript -- if so, you'll need to resort to a script or Firefox plugin to get them too.

link|flag
Like I said in the comment for my first post it seems it has been fixed in v1.12. I still don't know how to include images that are on other servers though. – mikael Oct 14 at 0:32
yep, parsing the CSS is new in wget v1.12, it's at the top of the changelog: freshmeat.net/urls/… – ~quack Oct 14 at 0:41
vote up 0 vote down

(This should be a comment on quack's answer) Try adding the option -H to the list. It stands for --span-hosts and allows downloading of content from external hosts.

link|flag

Your Answer

Get an OpenID
or
never shown

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