-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.py
54 lines (46 loc) · 1.44 KB
/
get.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
45
46
47
48
49
50
51
52
53
54
import requests
from bs4 import BeautifulSoup
import re
import sys
key = sys.argv[1]
r = requests.get('https://www.sanskrit-lexicon.uni-koeln.de/cgi-bin/monier/monierv1a.pl?key=' + key + '&filter=SktRomanUnicode&noLit=off&transLit=SLP2SLP&scandir=../..MWScan/MWScanpng&filterdir=../../docs/filter')
def get_head_word(head):
word = ""
for el in head.find_all('font'):
if 'color="blue"' in str(el):
word = el.contents[0]
return word
doc = r.content
soup = BeautifulSoup(doc, 'html.parser')
table = soup.find_all('td')
heads = []
for td in table:
for n in range(1, 100):
s = 'H' + str(n)
if s in str(td):
heads.append(td)
break
cur_head = ""
meanings = {}
for td in table:
if td in heads:
cur_head = td
meanings[cur_head] = []
else:
meanings[cur_head].append(td)
#ptrn = re.compile("</*\s*a[^>]*>(.*?)")
ptrn1 = re.compile("</*\s*[^>]*>")
ptrn2 = re.compile("\&\;c")
ptrn3 = re.compile("\[L\=[0-9]+\]")
for head in heads:
mngs = meanings[head]
print(get_head_word(head))
print("-----------------------------------------------------------------------")
for m in mngs:
m_ = re.sub(ptrn1, "", str(m))
m_ = re.sub(ptrn2, "", m_)
m_ = re.sub(ptrn3, "", m_)
m_ = m_.rstrip().lstrip()
if m_ != "":
print("-> " + m_)
print("=======================================================================")