Simple Python Script To Search Wikipedia From The Command Line / by Joseph Palumbo

If you’re like me, you don’t like to take your fingers off the keyboard. And if, like me, you’re a keyboard cowboy, you probably do a lot of work from the command line.

I’m always looking for ways to increase my productivity by adding more tools and functionality to my command line. So here’s a very simply python script using Selenium to search Wikipedia from CLI.

from selenium import webdriver
from sys import argv # Include file to upload
import sys

# unpacks the arguments passed on the command line
script = argv[0]

# joins multiple strings into one to create search_term
search_term = ' '.join(sys.argv[1:])

# test is variable is set
except NameError:
    print 'Please enter search term'
    browser = webdriver.Firefox()
    # content = driver.find_element_by_css_selector('p.content')

Once you have this you need to crease a bash alias to be able to access it easily. I created the following:

alias wiki='python /Users/palumbo/code/tools/'

Now anytime I want to look up something in Wikipedia, I just need to type wiki <search term> into my terminal and it brings up a new Firefox window with the wikipedia page for that term.