-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdefine.py
More file actions
32 lines (24 loc) · 718 Bytes
/
define.py
File metadata and controls
32 lines (24 loc) · 718 Bytes
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
import requests
from bs4 import BeautifulSoup
import sys
'''
This code uses Dictionary.com for the definitions of the words
'''
word = sys.argv[1]
url = "https://www.dictionary.com/browse/" + word
try:
r = requests.get(url)
bs = BeautifulSoup(r.text,'html.parser')
except:
print("Invalid Reqest")
try:
#Part of Speech
pos = bs.findAll("span", {"class":"luna-pos"})
print("\n" + word+ ": " + pos[0].text + "\n")
#Definitions
lists = bs.findAll("ol")
definitions =lists[0].findChildren("li", recursive=False)
for (i,definition) in enumerate(definitions):
print(str(i+1), definition.text)
except:
print("Word not Found")