forked from elig0n/morfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pymilon.+.py
executable file
·46 lines (39 loc) · 1.05 KB
/
pymilon.+.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
39
40
41
42
43
44
#!/usr/bin/env python3
import pyperclip
import requests
try:
from BeautifulSoup import BeautifulSoup
except ImportError:
from bs4 import BeautifulSoup
## Get text from clipboard
text=pyperclip.paste()
## base URL
url = 'http://www.morfix.co.il/'
## read URL
def getHtml():
try:
r = requests.get(url+text)
except IndexError:
r = 1
return r
## extension title
print("PyMilon\n--")
## extension output
if len(text.split(' ')) > 3:
print("No term specified")
else:
r = getHtml()
if r == 1:
print("No term specified")
else:
try:
html = r.content
parsed_html = BeautifulSoup(html, "lxml")
result = parsed_html.body.find('div', attrs={'class':'default_trans'}).text
print(result)
except AttributeError:
try:
result = parsed_html.body.find('div', attrs={'class':'translation translation_he heTrans'}).text
print(result)
except AttributeError:
print("No term specified")