Skip to content

Instantly share code, notes, and snippets.

@larsr
Created May 7, 2013 13:31
Show Gist options
  • Save larsr/5532572 to your computer and use it in GitHub Desktop.
Save larsr/5532572 to your computer and use it in GitHub Desktop.
Fetch synonyms and antonyms from thesaurus.com
import BeautifulSoup
import urllib2
def word(w):
return BeautifulSoup.BeautifulSoup(urllib2.urlopen("http://thesaurus.com/browse/"+w).read())
def synonym(w):
w = word(w)
return w.find('table', {"class":'the_content'}).find('td',text=lambda t:'Synonym' in t).parent.parent.text
def antonym(w):
w = word(w)
return w.find('table', {"class":'the_content'}).find('td',text=lambda t:'Antonym' in t).parent.parent.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment