Using the Python Documentation I found the HTML parser but I have no idea which library to import to use it, how do I find this out (bearing in mind it doesn't say on the page).
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Try:
In Python 3.0, the HTMLParser module has been renamed to html.parser you can check about this here
Python 3.0
Python 2.2 and above
You probably really want BeautifulSoup, check the link for an example.
But in any case
For real world HTML processing I'd recommend BeautifulSoup. It is great and takes away much of the pain. Installation is easy.
You may be interested in lxml. It is a separate package and has C components, but is the fastest. It has also very nice API, allowing you to easily list links in HTML documents, or list forms, sanitize HTML, and more. It also has capabilities to parse not well-formed HTML (it's configurable).
I would recommend using Beautiful Soup module instead and it has good documentation.
You should also look at html5lib for Python as it tries to parse HTML in a way that very much resembles what web browsers do, especially when dealing with invalid HTML (which is more than 90% of today's web).