command-line Google

Because I was bored today, and do such things when I’m bored, I came up with a command-line interface for Google in Python using Google’s web search JSON API.

Hafnia % google-search -n 1 "Google"
Google (
 * Enables users to search the Web, Usenet, and images. Features include
   PageRank,   caching and translation of results, and an option to find similar

Strangely enough, Google seems to leave bold tags (as well as an entity or two) in the “content” section of their search results on this API, so I ended up using lxml to parse the HTML into plain text, but other than that, google-search doesn’t use anything outside of the stdlib.

EDIT: I changed the script to use string modification so that lxml is no longer necessary. If I feel like it, I might put all of the text processing into something more suited for it …

Rather than pasting the source code here, I’ll just link to google-search on my website.