#!/usr/bin/python
from bs4 import BeautifulSoup as bs
import re
from requests import get
def remove_non_ascii(text):
return re.sub(r'[^\x00-\x7F]+', '', text)
def get_soup(url):
raw = remove_non_ascii(get(url).content)
soup = bs(raw)
return soup.select("#MainTxt")[0].select('.ds-single')[0].text.strip()
def lookup(word):
base_url = "http://www.thefreedictionary.com/"
query_url = (base_url + word)
return get_soup(query_url)
if __name__ == '__main__':
print lookup('linux')