-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHTMLTableStripMod.py
More file actions
70 lines (48 loc) · 1.92 KB
/
HTMLTableStripMod.py
File metadata and controls
70 lines (48 loc) · 1.92 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 22 09:29:15 2014
@author: adminGH
Script to get subdirectories and filenames
"""
root = os.getcwd()
path = os.path.join(root, 'strip_table', 'testsub')
# create list to store file names
fname = []
fold = []
for path, subdirs, files in os.walk(path):
for name in files:
if ".htm" in name:
# create lists of files and folders
fname.append(name)
fold.append(path)
# Open html files for editing
fileIN = open(os.path.join(path, name), "r")
# read in Mylines variable
html = fileIN.readlines()
fileIN.close()
# first table tag entry
ChkTop = "<table"
end = ">"
# last table tag entry
ChkBot = "</table>"
# serach for tags and remove top <table>
for i in html:
if ChkTop in i:
top = i[:-len(end)]
html.remove(i)
break
# reverse html to remove bottom tag
list.reverse(html)
for i in html:
if ChkBot in i:
bot = i[:-len(end)]
html.remove(i)
break
# reverse back to original format
list.reverse(html)
# overwrite existing file with new list
outFile = 'mod' + name
fileOUT = open(os.path.join(path, outFile), "w")
for i in html:
fileOUT.write("%s" % i)
fileOUT.close()