Created
May 7, 2013 13:31
-
-
Save larsr/5532572 to your computer and use it in GitHub Desktop.
Fetch synonyms and antonyms from thesaurus.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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