This is a basic Python code to retrieve data behind trajectories plotted on the Google Books Ngram Viewer. Just type in the same string you would have entered on books.google.com/ngrams, and retrieve the data in tsv format. By default, data is printed on screen and saved to the current directory. For more on the types of queries accepted, see this info page.
Note to savvy users:
(1) you can directly pass queries as arguments, such as
(2) if you pass the '-quit' flag as an argument, the program will run once and quit without asking for more input:
(3) Known caveat: quotation marks are removed from the input query.
(4) License: none, please distribute, modify and improve as you see fit.
PLEASE do respect the terms of service of the Google Books Ngram Viewer while using this code. This code is meant to help viewers retrieve data behind a few queries, not bang at Google's servers with thousands of queries. The complete dataset can be freely downloaded directly on Google's website.
This code is not a Google product and is not endorsed by Google in any way. Contact us at firstname.lastname@example.org, @culturomics or @jb_michel
With this in mind... happy plotting!