How to read information from tables in HTML?

Stefan Behnel stefan.behnel-n05pAM at web.de
Fri Aug 3 13:23:26 CEST 2007


ZelluX wrote:
> I'm confronted with some trouble when dealing with html files.
> 
> The html files contain javascript and some information stored in tables.
> And it seems that they're not well-formed, when parsed with minidom, it
> will say "mismatched tag".

minidom deals with XML. You're trying to read something that's (similar to)
HTML. HTML is much less strict.


> Then how can i get information from those files? Is there any useful
> library for me?

BeautifulSoup or lxml.html (which supports the BeautifulSoup parser, btw).

Both can deal with broken HTML, but lxml.html has better support for cleaning
up HTML (e.g. removing Javascript or embedded content, etc.) or handling forms.

http://codespeak.net/lxml/

The lxml.html package is not currently in an official lxml release, but you
can install it from SVN sources:

http://codespeak.net/svn/lxml/branch/html/

A release is expected soon.

Stefan



More information about the Python-list mailing list