Question: Python3.6 Need copy code 3. Write class HeaderParser that is a subclass of the HTMLParser class. It will find and collect the contents of all
3. Write class HeaderParser that is a subclass of the HTMLParser class. It will find and collect the contents of all the headings in an HTML file fed to it. The parser works by identifying when a header tag has been encountered and setting a boolean variable in the class to indicate that. When the data handler for the class is called and the boolean in the class indicates that a header is currently open, the data inside the header is added to a list. Finally, when a closing header tag is encountered the boolean variable is unset. To implement this parser you will need to override the following methods of the HTMLParser class: 1. init: The constructor calls the parent class constructor, set the boolean variable in the object appropriately, and sets the list of headings to the empty list. the header indicator should be set header indicator should be unset. 2. handle starttag: If the tag that resulted in this method being called is a header, 3. handle endtag: If the tag that resulted in this method being called is a header, the 4. handle data: If the parser is currently inside a header, then the data should be added to the list of headers contents. Make sure that you strip any leading or trailing spaces or newlines off the contents of the header before adding it to the list 5. getHeadings: The function returns the list of headings gathered by the parser You can find a template for the class and a test function testHParser) in the lab zip file. The following shows what that test function would display on several sample web pages. Note that your solution must work on any page, not just the ones provided here. Think carefully about what it means to collect headings in a general context >>> testHParser ('http://zoko.cdm.depaul.edu/csc242/headers.html') ["Header l',"Heade 2', 'Header 3, Header 4, 'Header 5', "Header 6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
