This module is unmaintained.
ClientTable is a Python module for generic HTML table parsing. It
is most useful when used in conjunction with other parsers
HTMLParser, regular expressions,
etc.), to divide up the parsing work between your own code and
import ClientTable import urllib2 response = urllib2.urlopen("http://www.acme.com/tables.html") tables = ClientTable.ParseFile(response, collapse_whitespace=1) table = tables # Indexing a table with a string-like object gets the column under that # header. ClientTable uses the first row of headers in the table by # default. assert str(table.headers_row) == "Widget production" row = table col = table["Widget production"] cell = col cell2 = row["Widget production"] cell3 = row.get_cell_by_nr(0) assert cell is cell2 is cell3 # HTMLTables are Python 2.2 iterators print ", ".join(table.headers) for row in table: # TableRows are sequences if row.is_header: continue print ", ".join(map(str, row)) # HTMLTable.col_iter returns a Python 2.2 iterator over columns for col in table.col_iter(): # TableColumns are sequences, too col_data = filter(lambda item: not item.is_header, col) col_data = map(lambda el: int(str(el)), col_data) print "sum of", col.header, "=", reduce(lambda x,y: x+y, col_data)
Python 2.2 or above is required. I will probably backport it to at least Python 2.0 later.
WARNING: This is an alpha release: interfaces will change, and don't
expect everything to work! I'm looking for feedback on the API ATM, so
comments are particularly welcome.
One thing that will certainly change is the way column headers are
specified by indexing, and by the various
methods. At the moment, an exact match is required. I plan to change
this so a substring match is the default, with regular expression
search, tag-stripping and exact matching as optional arguments.
nr_toplevel_to_parse arguments to
are yet to be implemented.
Of course not!
The MIT license.
You get the same cell object back more than once when indexing or iterating (unless you pass the single_span (NOT IMPLEMENTED YET) argument to ParseFile).
Pass the strip_tags argument to ParseFile. Note that headers are cells, too.
I prefer questions and comments to be sent to the mailing list rather than direct to me.
John J. Lee, May 2006.