Skip to content

Instantly share code, notes, and snippets.

@htoukour
Last active November 22, 2017 07:28
Show Gist options
  • Save htoukour/4587eaf4b8c0048ce45f8ba81c951485 to your computer and use it in GitHub Desktop.
Save htoukour/4587eaf4b8c0048ce45f8ba81c951485 to your computer and use it in GitHub Desktop.
A Simple Dictionary Script.
import re
import urllib.request
try:
url = "http://dictionary.reference.com/browse/"
#This will be our Url where we'll pulled the definition.
word = input("Enter your word: ")
url = url + word
data = urllib.request.urlopen(url).read()
data1 = data.decode("utf-8")
#To remove any encoding issue.
m = re.search('meta name="description" content="', data1)
start = m.end()
end = start + 300
newString = data1[start: end]
m = re.search("See more.", newString)
end = m.start() - 1
definition = newString[0:end]
print(definition)
except:
print("Sorry, can't find "+word+" in the dictionary.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment