Lycoris53 commited on
Commit
003505d
1 Parent(s): 446918d

Create amitaro_html_parse.py

Browse files
Files changed (1) hide show
  1. amitaro_html_parse.py +48 -0
amitaro_html_parse.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from bs4 import BeautifulSoup
2
+
3
+ if __name__ == "__main__":
4
+ f = open("./amitaro.htm", "r")
5
+ txt = f.read()
6
+ soup = BeautifulSoup(txt)
7
+
8
+ import json
9
+ f = open('amitaro.json')
10
+ file_list = json.load(f)
11
+
12
+ td = soup.find_all('td')
13
+ for i, val in enumerate(td):
14
+ if len(val.contents) == 0:
15
+ continue
16
+ key = val.contents[0]
17
+ if key in file_list:
18
+ #print(td[i-1].contents[0])
19
+ if len(td[i-1].contents) > 0:
20
+ #print(td[i-1].contents[0])
21
+ temp = BeautifulSoup(str(td[i-1].contents[0]))
22
+ a = temp.find_all('a')
23
+ print(a[0].contents[0])
24
+ file_list[key]["kana"] = str(a[0].contents[0])
25
+
26
+ for key, val in file_list.items():
27
+ val["path"] = "./amitaro/" + val["path"]
28
+
29
+ with open("./amitaro_with_kana.json", "w") as outfile:
30
+ outfile.write(json.dumps(file_list, indent=4,ensure_ascii=False))
31
+
32
+ file = []
33
+ for key, val in file_list.items():
34
+ if len(val['kana']) == 0:
35
+ continue
36
+ if val['kana'].find("(") != -1:
37
+ continue
38
+ file.append(f"{val['path']}|0|{val['kana']}")
39
+
40
+ amitaro_train = []
41
+ amitaro_val = []
42
+ for val in file:
43
+ amitaro_train.append(val)
44
+
45
+ f = open("amitaro_train.txt", "w")
46
+ for val in amitaro_train:
47
+ f.write(f"{val}\n")
48
+ f.close()