56

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?

3 Answers 3

101
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.

7
  • 1
    I know...! Nice eh? ;) Nov 10, 2011 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. Nov 10, 2011 at 1:03
  • WOW + amazing. THX u roc good idea.
    – Kangarooo
    Nov 10, 2011 at 3:50
  • @BrunoPereira, I am also trying to download google spreadsheet file. But I could not find the link for the file. Could you please say how to get the link for a google spreadsheet file so that I can use wget in the same way as Chinmay Kanchi. Thanks in advance.
    – user22180
    Oct 15, 2014 at 9:29
  • @ChinmayKanchi I call myself a web programmer last 15 years, but when it comes to this I always try and use a more meaningful name in code.
    – tishma
    Oct 20, 2016 at 6:00
5

You can try to use curl to download and keep original filename:

curl -OJL ${your_url}
  • -O for remote-name
  • -J for remote-header-name
  • -L for location

see curl command line options.

0

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/.

2
  • 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. Nov 10, 2011 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, 2011 at 1:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .