0% found this document useful (0 votes)
30 views1 page

Definition

The document contains a Python script that takes in a user input word, looks it up in an online dictionary, and prints the definition. It uses regular expressions and URL handling to retrieve and parse the definition from the dictionary page.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views1 page

Definition

The document contains a Python script that takes in a user input word, looks it up in an online dictionary, and prints the definition. It uses regular expressions and URL handling to retrieve and parse the definition from the dictionary page.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

import re

import urllib.request

try:
url = "http://dictionary.reference.com/browse/"

word = input("Enter your word: ")

url = url + word

data = urllib.request.urlopen(url).read()
data1 = data.decode("utf-8")

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("I'm sorry, you're word is not in the dictionary.")

You might also like