Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Tag: #Constructor - initializes the instance variables __tag_name and __tag_type def __init__(self,tag_name,tag_type): self.__TYPE_LIST = [start,end,empty] self.__tag_name = tag_name try: self.__tag_type = self.__TYPE_LIST[tag_type] except: raise

image text in transcribedimage text in transcribed

class Tag: #Constructor - initializes the instance variables __tag_name and __tag_type def __init__(self,tag_name,tag_type): self.__TYPE_LIST = ["start","end","empty"] self.__tag_name = tag_name try: self.__tag_type = self.__TYPE_LIST[tag_type] except: raise Exception("Invalid tag type")

#Returns the tag name def get_tag_name(self): return self.__tag_name #Returns the tag type def get_tag_type(self): return self.__tag_type #Checks whether two tags are matching tags - an opening and closing pair def is_match(self,other): if(self.__tag_name == Other.__tag_name): if((self.__tag_type == "start" and Other.__tag_type == "end") or (self.__tag_type == "end" and Other.__tag_type == "start")): return True else: return False else: return False #Checks whether two tags are the same. #Tags are the same only if they have the same name and are of the same type. def __eq__(self,other): if(self.__tag_name == Other.__tag_name and self.tag_type == Other.tag_type): return True else: return False

#Returns string representation of tag def __str__(self): if (self.__tag_type == "start"): return "String representation of Tag is : ."

elif(self.__tag_type == "end"): return "String representation of Tag is : "+self.__tag_name+"> ."

else: #returned only tag name if the tag type is Empty return "String representation of Tag is : "+self.__tag_name

2) Processing the input file With the Tag class complete, you must now implement a function that will read an HTML file, extract the HTML tags and return them in a list. To do this you wil need to complete the process_html file ) function in the HTML_Proressor_abcd001.py file. Here is a COMPSCI 105 S2 C - Assignment One 11 of 13 simple algorithm you can follow: Create an empty list to store the tags you encounter Read one character at a time from the data file, ignoring everything until you get to a" (ignore the" as well). Read one character at a time, appending them to a string until you get to a" or a white space (ignoe the and the white space as well The string you have built is the name of the tag. Use this tag name to create an instance of the Tag class and append it to the list. Hint: end tags have a"/" before their name. Once you have gone through the data file and completed your list of tags, return it

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

What is a product/service feasibility analysis?

Answered: 1 week ago

Question

Question What integration level should an employer choose?

Answered: 1 week ago