3) HTML Tag Checker Complete the function tag_checker) in the HTML_Processor_abc
ID: 3746816 • Letter: 3
Question
3) HTML Tag Checker Complete the function tag_checker) in the HTML_Processor_abcd001.py file that iterates through your list of tags, looking for matches. If there is a mismatch of start and end tags, raise an exception with the appropriate error message (see output section below). To check whether a pair of tags match use the is match () method in the Tag class. After going through the list, if there are still tags remaining in the stack, raise an exception with the appropriate error message along with the tags in the stack (see output section below) Additionally your tag_checker function should keep track of the unique tags encountered using a list unique tags. As you iterate through your list of tags, check and see if the tag appears in this list. If it doesn't, add it to the list. Once you have gone the list of tags and have not encountered any mismatches, return the unique_tags list. Output The output of your program should include the following One line for each tag you check, explaining the action and displaying the current contents of the stack. You will need to complete the str method of the Stack class to allow the information to be displayed properly. Some examples are Tag pushed. Stack 1s now: [, , ] Tag is popped. Stack is now: [,, , , , , ,, ,Explanation / Answer
#Processes HTML file and returns list of HTML tag objects def process_html_file(file_name): empty_tags = ['br','img','meta','hr','1ink','base'] input_file = open(file_name, "r") htmlString = input_file.read() input_file.close() tags = [] currentTag = '' tagStarted = False for c in htmlString: if c == '' or c.isspace(): tagStarted = False # ignore empty tags if not currentTag.strip('/') in empty_tags: if '/' in currentTag: tags.append(Tag(currentTag.strip('/'), 1)) else: tags.append(Tag(currentTag, 0)) currentTag = '' else: currentTag += c return tags #Goes through list of HTML tag object: and checks whether the tags are ball def tag_checker(tag_list): myStack = Stack() for tag in tag_list: if tag.get_tag_type() == 'end': if myStack.isEmpty() : return False popped = myStack.pop() if not popped.is_match(tag): return False elif tag.get_tag_type() == 'start': myStack.push(tag) return myStack.isEmpty()Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.