Skip to main content

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 | RSS feed

This version

0.2

Download files

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

Source Distribution

table2dicts-0.2.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file table2dicts-0.2.tar.gz.

File metadata

  • Download URL: table2dicts-0.2.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for table2dicts-0.2.tar.gz
Algorithm Hash digest
SHA256 e23c96d403e0b645dd7519704728febba231b1ed7249100fbe5cd73684059a75
MD5 edb031206649f15010527634e85700f4
BLAKE2b-256 7f1b3a7af2445c7d8cd153768afd16c4866834d030b357eae6198a34b8d43dc1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page