Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When using wget in a script to download some files from Google Docs, the name of the file is not preserved. For example:

wget 'http://spreadsheets.google.com/pub?key=pyj6tScZqmEfbZyl0qjbiRQ&output=xls' 

saves the file as pub?key=pyj6tScZqmEfbZyl0qjbiRQ instead of indicatorhivestimatedprevalence15-49.xls, which is what I get if I click on the link in a browser. Is there any way to enforce this "browser-like" behaviour in wget?

share|improve this question

2 Answers 2

up vote 21 down vote accepted
wget --content-disposition 'http://spreadsheets.google.com/pub?key=pyj6tScZqmEfbZyl0qjbiRQ&output=xls'

will do the trick for you.

Its still not fully implemented and seems to bug out a bit sometimes so its not the default option in wget, use it at your own risk.

share|improve this answer
    
Excellent, this works! –  Chinmay Kanchi Nov 10 '11 at 0:25
1  
I know...! Nice eh? ;) –  Bruno Pereira Nov 10 '11 at 0:27
    
I'm not really much of a web programmer, so I would have never thought of looking for the phrase "content disposition". You saved me having to manually look at the HTTP headers, discover the content-disposition header and deal with it. –  Chinmay Kanchi Nov 10 '11 at 1:03
    
WOW + amazing. THX u roc good idea. –  Kangarooo Nov 10 '11 at 3:50
    
Hooray! Thanks Bruno. –  Steve Bennett Feb 18 at 3:20

The Google Docs link is really telling a script on the server to run, parsing that into the file you want. The file, to the best of my knowledge, does not exist ever on the server in the els form, but is generated at runtime when you ask for it. Thus, there isn't anything for wget to get.

In order to download the file, you would need to use the google API http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#DownloadingDocs/.

share|improve this answer
    
Yes, the server is asking a script to run, which creates the .xls file on the fly. However, a full-blown browser has no problem with this. So it's obviously possible to do without the Docs API. –  Chinmay Kanchi Nov 10 '11 at 0:16
    
My thought had been that the script run in the browser would use the API, so to do it without the browser, one would have to recreate the script. Interesting that wget has a flag for it. –  Ethan Nov 11 '11 at 1:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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