"""The following routines are specific to queries to www.dictionary.com (as of 2003-07-23)""" def get_def_page(word): """Retrieve the definition page for the word of interest. """ import urllib url = "http://www.dictionary.com/cgi-bin/dict.pl?term=%s" % word fo = urllib.urlopen(url) page = fo.read() return page def get_definitions(wlist): """Return a dictionary comprising words (keys) and a definition lists (values). """ ddict = {} for word in wlist: text = get_def_page(word) defs = extract_defs(text) ddict[word] = defs return ddict def extract_defs(text): """The site formats its definitions as list items
  • definition
  • We first look for all of the list items and then strip them of any remaining tags (like