In this video, Kathryn shows you how to parse HTML in python using the HTML parser module. Learn how to create a parser, as well as how to feed in data from your code, live input, and files on your computer.
- [Instructor] Let's use the HTML Parser Module…to parse 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 HTML Parser 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 a 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 h1 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 HTML Parser 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 from the…HTML Parser class that we imported.…One method we're going to overwrite is def handle_starttag…
- Working with logical and comparison operators
- Getting a list of numbers with the range() and list() functions
- Using mathematical functions such as round(), abs(), and pow()
- Calculating a given input's length
- Importing and using the math module
- Reading a user's command-line arguments
- Getting the current time
- Formatting dates and times with datetime
- Creating a timer
- Using urllib to get content from the Internet
- Using the JSON module to decode content
Skill Level Intermediate
1. Python: What's Built-In?
2. Python: Math
3. Python: Input/Output
4. Python: Date & Time, HTML Parsing, and HTTP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.