From the course: Learning the Python 3 Standard Library

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Python HTML parser module

Python HTML parser module

- [Instructor] Let's use the HTML Parson module to parser some HTML code in Python. And so in order to parse HTML code, we have to import the HTML parser module, and so to do this, we'll go from html.parser, and from this parser we'll import the HTMLParser class. However, before we get into parsing, let's review some HTML. In HTML we have two types of tags, opening tags and closing tags. Here, we have an opening paragraph tag which starts a paragraph, and the closing paragraph tag that ends a paragraph. We also have comments in HTML that are like notes to the developer, and then we have a full line of code with an opening each one tag, hi there as our data, and then a closing header one tag. Here, we're going to create a new class that inherits from the HTMLParser class, and then we're going to overwrite some methods from the inheriting class. And so we're going to go class HTMLParser, and then we're inheriting…

Contents