3

I'm trying to use wget to automatically download a wallpaper. Here is the command:

wget http://static.die.net/earth/mercator/1600.jpg

However, if I try to open the resulting picture, it seems to say it has a bad magic number. By running file 1600.jpg, I get 1600.jpg: GIF image data, version 89a, 1 x 1. If I open it as a GIF it doesn't work either. It's only 37 bytes too.

It works perfectly fine if I view or download it through Firefox.

Any ideas?

6

I think it's some kind of protection against direct downloads, nothing wrong with wget (the server is sending you a transparent 1x1 GIF image).

You can circumvent this by using wget with the -U flag, adding the user agent string of your browser, eg.:

wget -U "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.17 (KHTML, like Gecko) Ubuntu/11.04 Chromium/11.0.654.0 Chrome/11.0.654.0 Safari/534.17" http://static.die.net/earth/mercator/1600.jpg

BUT: You should first ask the owner of that website if it's ok to download the content this way. There has to be a reason why the usual wget approach is blocked (maybe it's intentional, maybe it's just misconfiguration).

  • 2
    I see. But why isn't Firefox affected? And how would I get around that? – rovaughn Feb 5 '11 at 17:10
  • 1
    @alecRN: See update. – htorque Feb 5 '11 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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