从命令行以TSV格式下载/导出公共Google Spreadsheet? [英] Download/Export Public Google Spreadsheet as TSV from Command Line?
问题描述
我有一个公开的(已发布的)Google电子表格,我试图以编程方式以TSV格式下载。
I have a public (published) Google spreadsheet that I’m trying to download programmatically in TSV form.
在我的浏览器中,激活了Google登录后,对于某些实际键 $ key
, https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=$key&exportFormat=tsv
起作用并生成TSV文件。
In my browser, with a Google login active, for some actual key $key
, https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=$key&exportFormat=tsv
works and produces a TSV file.
但是在我的外壳中:
-
curl -L https:// spreadsheets。 google.com/feeds/download/spreadsheets/Export?key=$key&exportFormat=tsv
生成一堆JavaScript。 -
curl -L https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=$key&exportFormat=csv
还会生成一堆JavaScript。 -
curl -L https://docs.google.com/spreadsheet/pub?key=$key&single=true&gid=0&output=csv\"
工作并生成CSV文件。 -
curl -L https://docs.google.com/spreadsheet/pub?key=$ key& single = true& gid = 0& output = tsv
会生成错误消息。
curl -L "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=$key&exportFormat=tsv"
produces a bunch of javascript.curl -L "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=$key&exportFormat=csv"
also produces a bunch of javascript.curl -L "https://docs.google.com/spreadsheet/pub?key=$key&single=true&gid=0&output=csv"
works and produces a CSV file.curl -L "https://docs.google.com/spreadsheet/pub?key=$key&single=true&gid=0&output=tsv"
produces an error message.
(尝试使用 w get
产生了相似的结果。)
(Attempts to use wget
produced similar results.)
我如何进行这项工作?到目前为止,我所能找到的所有Google文档都针对更复杂的问题,而不是简单的下载和格式更改,并且如果我的问题的解决方案在某个地方,我还找不到它。
How do I make this work? All the Google documentation I’ve been able to find so far is geared towards much more complicated problems than a simple download and format change, and if the solution to my problem is in there somewhere, I haven’t been able to find it yet.
推荐答案
我发现这很令人沮丧,没有记录在案。我确定它已记录在某处...但我从未找到它。
I found this to be frustratingly undocumented. I'm sure it's documented somewhere... but I never found it.
前提是您的Google表格是公开发布的。这对于许多人来说并不直观。 (选择文件->发布到Web ...)
The premise is that your Google Sheet is published publicly. This is not intuitive for many folks. (Choose File -> Publish to Web...)
发布表格时,您会得到一个要复制的网址:
https://docs.google.com/spreadsheets/d/1XsfK2TN418FuEstNGG2eI9FmEV-4eY-FnndigHWIhk4/pubhtml
When you publish a sheet, you are given a url like this to copy:
https://docs.google.com/spreadsheets/d/1XsfK2TN418FuEstNGG2eI9FmEV-4eY-FnndigHWIhk4/pubhtml
该网址很好可浏览...但不是我想要的可下载CSV。通过漫长的搜索和反复试验,我得出了以下结论:
That url is nicely browsable... but it's not the downloadable CSV I wanted. Through a lengthy combination of search and trial-and-error I came up with this:
curl https://docs.google.com / spreadsheets / d / 1XsfK2TN418FuEstNGG2eI9FmEV-4eY-FnndigHWIhk4 / export?gid = 0& format = csv
我发现它非常有用。我希望有人在评论中提供指向官方文档的链接,以更详细地说明这一点。
I find it to be tremendously helpful. I hope somebody comments with a link to the official docs explaining this in more detail.
这篇关于从命令行以TSV格式下载/导出公共Google Spreadsheet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!