wget normally stops when it gets a HTTP error, e.g. 404 or so. Is there an option to make wget to download the page content regardless of the HTTP code?

link|improve this question

75% accept rate
3  
You can use curl instead. – Daniel Beck Mar 6 '11 at 8:49
feedback

1 Answer

up vote 3 down vote accepted

Use curl when wget fails.

#!/bin/bash

if ! wget $1 
    then curl -R -O $1
fi

Usage (saved as wget.sh):

404 error will be saved with curl:

$ ./wget.sh http://www.google.com/asdasdasdasd.html

Working URL will be saved with wget:

$ ./wget.sh http://www.google.com/
link|improve this answer
...but then why use wget at all? – grawity Mar 6 '11 at 14:36
It depends on what you want to do. Wget can download recursively, for instance. Read more: daniel.haxx.se/docs/curl-vs-wget.html – Fábio Perez Mar 6 '11 at 14:39
But not when you give it one URL, as in your script and examples. And scripts wouldn't work with recursive wget. – grawity Mar 6 '11 at 15:34
@grawity I created that script just for example purposes. – Fábio Perez Mar 6 '11 at 15:48
feedback

Your Answer

 
or
required, but never shown

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