-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableProcess.py
32 lines (30 loc) · 1.14 KB
/
tableProcess.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
import re
def tableProcess(htmls):
pattern = r"<table"
m1 = re.search(pattern, htmls).span()[0]
pattern = r"</table>"
m2 = re.search(pattern, htmls).span()[1]
htmls = htmls[m1:m2]
htmlsLines = htmls.split('\n')
htmlsLines[0] = '<table align="center" border="1" cellpadding="5" cellspacing="0">'
# print(htmlsLines)
for i in range(0, len(htmlsLines)):
if '<tr>' in htmlsLines[i] or '</tr>' in htmlsLines[i]:
htmlsLines[i] = htmlsLines[i].lstrip("\t")
htmlsLines[i] = htmlsLines[i].lstrip()
htmlsLines[i] = "\t" + htmlsLines[i]
elif '<th' in htmlsLines[i] or '<td' in htmlsLines[i]:
htmlsLines[i] = htmlsLines[i].lstrip("\t")
htmlsLines[i] = htmlsLines[i].lstrip()
htmlsLines[i] = htmlsLines[i].replace(' class="tcenter"',"")
htmlsLines[i] = "\t\t" + htmlsLines[i]
else:
htmlsLines[i] = htmlsLines[i].lstrip("\t")
htmlsLines[i] = htmlsLines[i].lstrip()
# print(htmlsLines)
htmls = ""
for i in htmlsLines:
if i == "":
continue
htmls += i + "\n"
return htmls