I have a Google spreadsheet that has not been made public, but just available to anyone that has the access link. Though I can access the data in CSV format from my browser even when I am not logged into my Google account (that is, anonymous access is allowed), there is no way I can download the data from the command line using wget, for instante. I have found several web pages with some instructions to create the download URL, but so far I've had no success. Is there an easy, straightforward way of doing this or will I have to use some Google Data library to access that data?
5 Answers
Maybe I'm not correctly understanding what you're trying to do, but I found a solution in this article that works just fine for me.
In the article, the author creates a download link for the spreadsheet as an XLS file (using "&output=xls”), but I tried "&output=csv" and successfully downloaded a correct CSV file.
Here's the download link to my "Download Test Spreadsheet", constructed just the way the author of the article suggested, but with "csv" substituted for "xls":
https://docs.google.com/spreadsheet/ccc?key=0At2sqNEgxTf3dEt5SXBTemZZM1gzQy1vLVFNRnludHc&output=csv
The link is anonymous (i.e., "Anyone who has the link can view"), and I downloaded it without logging into my Google account. I'll admit that I didn't use wget to do it (I just used a browser -- I didn't have wget installed), but I can't think of a reason that wget wouldn't work just as well.
Actually, I just grabbed a copy of wget and tried it, and it downloads the file correctly too:
% wget --no-check-certificate --output-document=test.csv 'https://docs.google.com/spreadsheet/ccc?key=0At2sqNEgxTf3dEt5SXBTemZZM1gzQy1vLVFNRnludHc&output=csv'
< bla bla bla, reams of output from wget >
% cat test.csv
Foo,Bar,Baz
1,2,3
4,5,6
So there ya go...
UPDATING FOR 2018
As commented by @AndyMortimer, the new download URL is
https://docs.google.com/spreadsheets/d/<KEY>/export?gid=<GID>&format=csv
where <KEY>
and <GID>
can be obtained from your navigation's URL,
https://docs.google.com/spreadsheets/d/<KEY>/edit#gid=<GID>
PS: spreadsheets may have multiple workbooks, GID is the desired workbook ID. One-workbook-spreadsheet usually has gid=0
, but if you add more they'll have random numbers (the GID is preseved even changing tab-order).
So, using wget
and the same spreadsheet,
wget --no-check-certificate -O test.csv \
'https://docs.google.com/spreadsheets/d/0At2sqNEgxTf3dEt5SXBTemZZM1gzQy1vLVFNRnludHc/export?gid=0&format=csv'

- 13,174
- 24
- 167
- 304

- 1,982
- 3
- 27
- 35
-
1Just out of curiosity I tried fetching the file with wget using both "&output=xls" and "&output=txt", and both of these trials worked correctly as well. (The "txt" format causes the spreadsheet to be downloaded as a tab-delimited file, which was something I wouldn't have known if I hadn't started fooling around with this. So thanks! I learned a couple of new things in this process.) – Hephaestus Jun 02 '12 at 23:39
-
In the end, for no reasons I don't yet understand, I was not able to download the file. I could talk to the owner to make it public, so that was the end of the problem for me. Thanks for your answers anyway. – José María Mateos Jun 15 '12 at 16:53
-
Sure, no worries. I actually had no experience with any of that when I found your question -- I was trying to figure out how to do something similar at the time. So it was a good exercise for me to figure out how to do it, and much of my reason for answering was to document what I had discovered. Good that you were able to find such an effective alternate solution. :-) – Hephaestus Jun 15 '12 at 20:21
-
1Even though this question is quite old, I'm going to comment a bit. My problem was that I was not storing the cookie correctly. At the time, I was using a Python program to try to download this. This fixed the problem I was reporting: `# Cookie management` `opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(CookieJar()))` `csv_data = csv.reader(opener.open(url))` ``` – José María Mateos May 17 '14 at 07:19
-
1The link given in this answer is the old URL format. For examples with the new URL scheme, see http://stackoverflow.com/a/23394860/305913 . – Andy Mortimer Apr 10 '15 at 09:41
-
Thanks, This is so helpful – Nate Simonsen Feb 17 '21 at 22:01
I'm able to get a wget
-able URL from public spreadsheet URLs that look like this:
https://docs.google.com/spreadsheets/d/LONG_ID_STRING/edit?usp=sharing
by changing them to look like this:
https://docs.google.com/spreadsheets/d/LONG_ID_STRING/export?format=csv
so that my wget command would look like:
$ wget "https://docs.google.com/spreadsheets/d/LONG_ID_STRING/export?format=csv"
Make sure you share the spreadsheet first with the blue "Share" button in the top right, then "Get Sharable Link".

- 3,370
- 2
- 31
- 36
-
-
1I want to add that the second LONG_ID_STRING doesn't seem to matter. The following URL works fine: `https://docs.google.com/spreadsheets/d/LONG_ID_STRING/export?format=csv` – Arjun Guha Nov 19 '16 at 16:13
-
This solution worked for me. @ArjunGuha is correct. The seconds `LONG_ID_STRING` is not necessary. – Cory Schires Dec 16 '16 at 19:47
-
-
It is **not a solution** for multiple spreadsheets in same `LONG_ID_STRING`, because gets only the first spreadsheet. **How to get the correct spreadsheet by its *gid*?** See typical navegation URL as `https://docs.google.com/spreadsheets/d/LONG_ID_STRING/edit#gid=_ID_`. – Peter Krauss Feb 19 '18 at 03:36
-
This didn't work for me. I got a 302 error (Moved Temporarily), then it downloaded some HTML. I think it's because I'm not authenticated. Is there a way to include credentials in the wget request? – horseshoe7 Sep 10 '19 at 11:40
-
To access other tabs you need to click and get the gid of that tab, so:
https://docs.google.com/spreadsheets/d/1GxmL3bbejjGx-Ji7kzsnZLzkSaMrfX5WwgRAvvqfqpw/pubhtml?widget=true&%3Bheaders=false#gid=2120833204
Becomes:
https://docs.google.com/spreadsheets/d/1GxmL3bbejjGx-Ji7kzsnZLzkSaMrfX5WwgRAvvqfqpw/export?format=csv&id=1GxmL3bbejjGx-Ji7kzsnZLzkSaMrfX5WwgRAvvqfqpw&gid=2120833204

- 34,714
- 9
- 70
- 166

- 36,764
- 19
- 160
- 190
Now I can answer questions, so I will leave it answered for good (pasting from my previous comment).
My problem was that I was not storing the cookie correctly. At the time, I was using a Python program to try to download this. This fixed the problem I was reporting:
# Cookie management
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(CookieJar()))
csv_data = csv.reader(opener.open(url))

- 359
- 1
- 3
- 7
Ran into this problem and tried a few of the solutions. None were working perfectly so I wrote this curl which seems to do the job. You need to share your google spreadsheet with anyone who has the link for it to work
curl -o /path/to/file/you/want/csv/to/go.csv 'https://docs.google.com/spreadsheet/ccc?key=[the-id-of-your-spreadsheet]&output=csv' -L
the -L
is the trick here has google often moves the csv around but will send you a redirect link. -L
tells curl
to follow the redirects until it lands on the file.
you can find the id
of your spreadsheet by opening it in google drive and looking at the url
https://docs.google.com/spreadsheets/d/[idwillbehere]/edit#gid=0

- 1,684
- 1
- 14
- 17
-
1Please you must to show how to map `_BIG_BASE64_` and `_ID_` from `https://docs.google.com/spreadsheets/d/_BIG_BASE64_/edit#gid=_ID_` to your `curl`. There are no `ccc` and no `key ` args at spreadsheets (plural). – Peter Krauss Feb 19 '18 at 03:32