HTML Table Extractor
Note: This is a re-release of html-table-extractor of yuanxu-li, existing just because I've been waiting for too long for an actual release to fix the incorrect dependency (pipenv would refuse to install new version of BeautifulSoup using the original version 1.4.0). I've kept changes to a minimum, just to add this notice, fix setup.py to make it PyPI friendly, and change the PyPI package name.
HTML Table Extractor is a python library that uses Beautiful Soup to extract data from complicated and messy html table
Important links
- Repository: https://github.com/yuanxu-li/html-table-extractor
- Issues: https://github.com/yuanxu-li/html-table-extractor/issues
Installation
pip install 'beautifulsoup4==4.5.3'
pip install html-table-extractor
Usage
Example 1 - Simple
| 1 | 2 |
| 3 | 4 |
from html_table_extractor.extractor import Extractor
table_doc = """
<table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table>
"""
extractor = Extractor(table_doc)
extractor.parse()
extractor.return_list()
It will print out:
[[u'1', u'2'], [u'3', u'4']]
Example 2 - Transformer
| 1 | 2 |
| 3 | 4 |
from html_table_extractor.extractor import Extractor
table_doc = """
<table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table>
"""
extractor = Extractor(table_doc, transformer=int)
extractor.parse()
extractor.return_list()
It will print out:
[[1, 2], [3, 4]]
Example 3 - Pass BS4 Tag
| 1 | 2 |
| 3 | 4 |
from html_table_extractor.extractor import Extractor
from bs4 import BeautifulSoup
table_doc = """
<html><table id='wanted'><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table><table id='unwanted'><tr><td>not wanted</td></tr></table></html>
"""
soup = BeautifulSoup(table_doc, 'html.parser')
extractor = Extractor(soup, id_='wanted')
extractor.parse()
extractor.return_list()
It will print out:
[[u'1', u'2'], [u'3', u'4']]
Example 4 - Complex
| 1 | 2 | 3 |
| 4 | ||
| 5 | ||
from html_table_extractor.extractor import Extractor
table_doc = """
<table>
<tr>
<td rowspan=2>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td colspan=2>4</td>
</tr>
<tr>
<td colspan=3>5</td>
</tr>
</table>
"""
extractor = Extractor(table_doc)
extractor.parse()
extractor.return_list()
It will print out:
[[u'1', u'2', u'3'], [u'1', u'4', u'4'], [u'5', u'5', u'5']]
Example 5 - Conflicted
| 1 | 2 | 3 |
| 4 | ||
| 5 | ||
from html_table_extractor.extractor import Extractor
table_doc = """
<table>
<tr>
<td rowspan=2>1</td>
<td>2</td>
<td rowspan=3>3</td>
</tr>
<tr>
<td colspan=2>4</td>
</tr>
<tr>
<td colspan=2>5</td>
</tr>
</table>
"""
extractor = Extractor(table_doc)
extractor.parse()
extractor.return_list()
It will print out:
[[u'1', u'2', u'3'], [u'1', u'4', u'3'], [u'5', u'5', u'3']]
Example 6 - Write to file
| 1 | 2 |
| 3 | 4 |
from html_table_extractor.extractor import Extractor
table_doc = """
<table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table>
"""
extractor = Extractor(table_doc).parse()
extractor.write_to_csv(path='.')
It will write to a given path and create a new csv file called output.csv:
1,2
3,4
Team
Errors/ Bugs
If something is not working correctly, or if you have any suggestion on improvements, report it here
Copyright
Copyright (c) 2017 Justin Li. Released under the MIT License
Third-party copyright in this distribution is noted where applicable.
Metadata
Release files for isaacto-html-table-extractor 1.4.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| isaacto-html-table-extractor-1.4.0.1.tar.gz | 4.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| isaacto_html_table_extractor-1.4.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.1 kB
Release files / isaacto-html-table-extractor-1.4.0.1.tar.gz
| Download URL | isaacto-html-table-extractor-1.4.0.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d4bb3711118c2bee561b4e52ea3b0795eee9985894c826587d0e87dfd00dae5e
|
|
BLAKE2b-256 checksum How to use checksums |
6f7f067d4740f75b8146161c01d96bcc3b0fce888c9143abb6fd8d9eb9b9c17f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.5.3
|
Release files / isaacto_html_table_extractor-1.4.0.1-py3-none-any.whl
| Download URL | isaacto_html_table_extractor-1.4.0.1-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1388a02354d7b15d27e495864e49c504dc28707ee0a9f1621c636502b9e1f890
|
|
BLAKE2b-256 checksum How to use checksums |
8725e64c1beb6ad194485adcd3447366816537797dbe331e89ac1868dcb1ddf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.5.3
|
Security for isaacto-html-table-extractor 1.4.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.