Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Python module for converting a html table to a list of dictionaries.

Project description

https://travis-ci.org/moagstar/table2dicts.svg?branch=master

table2dicts

Python module for converting a html table to a list of dictionaries.

Installation

Installing from PyPI using pip:

$ pip install table2dicts

Installing from source:

$ python setup.py install

Usage

Give it some html with a table:

>>> table2dicts('''
...    <table>
...         <thead>
...             <tr><th>a</th><th>b</th><th>c</th></tr>
...         </thead>
...         <tbody>
...             <tr><td>1</td><td>2</td><td>3</td></tr>
...             <tr><td>4</td><td>5</td><td>6</td></tr>
...         </tbody>
...    </table>
... ''')
[OrderedDict([('a', '1'), ('b', '2'), ('c', '3')]), OrderedDict([('a', '4'), ('b', '5'), ('c', '6')])]

No thead or tbody, no problem:

>>> table2dicts('''
...    <table>
...        <tr><th>a</th><th>b</th><th>c</th></tr>
...        <tr><td>1</td><td>2</td><td>3</td></tr>
...        <tr><td>4</td><td>5</td><td>6</td></tr>
...    </table>
... ''')
[OrderedDict([('a', '1'), ('b', '2'), ('c', '3')]), OrderedDict([('a', '4'), ('b', '5'), ('c', '6')])]

When no th is present, the first row of td elements is used as a header:

>>> table2dicts('''
...    <table>
...        <tr><td>a</td><td>b</td><td>c</td></tr>
...        <tr><td>1</td><td>2</td><td>3</td></tr>
...        <tr><td>4</td><td>5</td><td>6</td></tr>
...    </table>
... ''')
[OrderedDict([('a', '1'), ('b', '2'), ('c', '3')]), OrderedDict([('a', '4'), ('b', '5'), ('c', '6')])]

Project details


Release history Release notifications

This version
History Node

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
table2dicts-0.2.tar.gz (2.4 kB) Copy SHA256 hash SHA256 Source None Jul 25, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page