Last active
November 22, 2017 07:28
-
-
Save htoukour/4587eaf4b8c0048ce45f8ba81c951485 to your computer and use it in GitHub Desktop.
A Simple Dictionary Script.
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 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