Question: 2. HTML supports ordered and unordered lists. An ordered list is defined using element ol and each item of the list is defined using element
2. HTML supports ordered and unordered lists. An ordered list is defined using element ol and each item of the list is defined using element li. An unordered list is defined using element ul and each item of the list is defined using element li as well. For example, the unordered list in file w3c.html is described using HTML code:
- Web for All
- Web on Everything
Develop class ListCollector as a subclass of HTMLParser that, when fed an HTML file, creates a Python list for every ordered or unordered list in the HTML document. Each item of a Python list should be the text data that appears in one item of the corresponding HTML list. You may assume that every item of every list in the HTML document contains only text data (i.e. no other HTML element). The class ListCollector should support method getLists() that takes no input arguments but returns a list containing all the created Python lists. >>> infile = open('htmlBasics.html') >>> content = infile.read() >>> infile.close() >>> myparser = ListCollector() >>> myparser.feed(content) >>> myparser.getLists() [['ordered', 'nested', 'CSS inline and internal styles'], ['inline styles', 'internal styles', 'images', 'tables', 'hyperlinks'], ['external', 'internal', 'email'], ['external', 'internal', 'email']] >>> >>> infile = open('lists.html') >>> content = infile.read() >>> infile.close() >>> myparser = ListCollector() >>> myparser.feed(content) >>> myparser.getLists() [['An item', 'Another', 'And another one'], File: w3c.html File: lists.html ['Item one', 'Item two', 'Item three', 'Item four']]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
