-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP06_GetMeaning.py
38 lines (29 loc) · 1004 Bytes
/
P06_GetMeaning.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Author: AKHILESH
# This script helps us to enter a word and get precise meaning for that word from vocabulary.com
import urllib.request
from bs4 import BeautifulSoup
word = input('Enter the word of which you want to find the meaning: ')
# Get the meaning by scrapping www.vocabulary.com
url = ("https://www.vocabulary.com/dictionary/" + word + "")
htmlfile = urllib.request.urlopen(url)
soup = BeautifulSoup(htmlfile, 'lxml')
soup1 = soup.find(class_="short")
# If certain word's meaning is not found
try:
soup1 = soup1.get_text()
except AttributeError:
print('Cannot find such word! Check spelling.')
exit()
# Print short meaning
print ('-' * 25 + '->',word,"<-" + "-" * 25)
print ("SHORT MEANING: ",soup1)
print ('-' * 65)
# Print long meaning
soup2 = soup.find(class_="long")
soup2 = soup2.get_text()
print ('-' * 65)
# Print instances like Synonyms, Antonyms, etc.
soup3 = soup.find(class_="instances")
txt = soup3.get_text()
txt1 = txt.rstrip()
print (' '.join(txt1.split()))