-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTML Checker.py
More file actions
111 lines (58 loc) · 1.7 KB
/
Copy pathHTML Checker.py
File metadata and controls
111 lines (58 loc) · 1.7 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
class Stack (object):
def __init__(self):
self.items = [ ]
def isEmpty (self):
return self.items == [ ]
def push (self, item):
self.items.append (item)
def pop (self):
return self.items.pop ()
def peek (self):
return self.items [len(self.items)-1]
def size (self):
return len(self.items)
def __str__(self):
return str(self.items)
##################################################
def getTag(string):
tagList = []
tagFound = False
tempString = ""
for character in string:
if character == ">":
tagFound = False
tagList.append(tempString)
tempString = ""
if tagFound:
tempString += character
if character == "<":
tagFound = True
return tagList
def checkTag(alist):
theStack = Stack()
index = 0
balanced = True
for tag in alist:
if tag[0] != "/":
theStack.push(tag)
print(theStack)
while index < len(alist) and balanced:
if tag[0] == "/":
if theStack.items[-1] in tag:
theStack.pop()
index += 1
return theStack
##################################################
def main():
txtFile = open("htmlfile.txt", "r")
fileString = ""
#theStack = Stack()
for line in txtFile:
fileString += line
tags = getTag(fileString)
theStack = checkTag(tags)
print(tags)
print(theStack)
#print(getTag(fileString))
#print(fileString)
main()