{"id":13597670,"url":"https://github.com/yuanxu-li/html-table-extractor","last_synced_at":"2025-04-10T05:33:03.079Z","repository":{"id":44341029,"uuid":"87861805","full_name":"yuanxu-li/html-table-extractor","owner":"yuanxu-li","description":"extract data from html table","archived":false,"fork":false,"pushed_at":"2020-05-01T18:40:12.000Z","size":32,"stargazers_count":84,"open_issues_count":7,"forks_count":23,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-24T01:20:25.318Z","etag":null,"topics":["beautifulsoup","crawler","extract-data","html","html-table","scraping","table"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuanxu-li.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-10T22:04:42.000Z","updated_at":"2024-04-19T19:50:08.000Z","dependencies_parsed_at":"2022-08-23T16:51:14.798Z","dependency_job_id":null,"html_url":"https://github.com/yuanxu-li/html-table-extractor","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanxu-li%2Fhtml-table-extractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanxu-li%2Fhtml-table-extractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanxu-li%2Fhtml-table-extractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanxu-li%2Fhtml-table-extractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuanxu-li","download_url":"https://codeload.github.com/yuanxu-li/html-table-extractor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248163312,"owners_count":21057909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beautifulsoup","crawler","extract-data","html","html-table","scraping","table"],"created_at":"2024-08-01T17:00:38.813Z","updated_at":"2025-04-10T05:33:02.768Z","avatar_url":"https://github.com/yuanxu-li.png","language":"Python","funding_links":[],"categories":["html"],"sub_categories":[],"readme":"# HTML Table Extractor\n[![Build Status](https://travis-ci.org/yuanxu-li/html-table-extractor.svg?branch=master)](https://travis-ci.org/yuanxu-li/html-table-extractor)\n\n_HTML Table Extractor is a python library that uses [Beautiful Soup](https://www.crummy.com/software/BeautifulSoup/) to extract data from complicated and messy html table_\n\n## Important links\n* Repository: https://github.com/yuanxu-li/html-table-extractor\n* Issues: https://github.com/yuanxu-li/html-table-extractor/issues\n\n## Installation\n\n```bash\npip install 'beautifulsoup4==4.5.3'\npip install html-table-extractor\n```\n\n## Usage\n\n### Example 1 - Simple\n\n\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e1\u003c/td\u003e\u003ctd\u003e2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n```python\nfrom html_table_extractor.extractor import Extractor\ntable_doc = \"\"\"\n\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e1\u003c/td\u003e\u003ctd\u003e2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\"\"\"\nextractor = Extractor(table_doc)\nextractor.parse()\nextractor.return_list()\n```\nIt will print out:\n```python\n[[u'1', u'2'], [u'3', u'4']]\n```\n\n### Example 2 - Transformer\n\n\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e1\u003c/td\u003e\u003ctd\u003e2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n```python\nfrom html_table_extractor.extractor import Extractor\ntable_doc = \"\"\"\n\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e1\u003c/td\u003e\u003ctd\u003e2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\"\"\"\nextractor = Extractor(table_doc, transformer=int)\nextractor.parse()\nextractor.return_list()\n```\nIt will print out:\n```python\n[[1, 2], [3, 4]]\n```\n\n### Example 3 - Pass BS4 Tag\n\n\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e1\u003c/td\u003e\u003ctd\u003e2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n```python\nfrom html_table_extractor.extractor import Extractor\nfrom bs4 import BeautifulSoup\ntable_doc = \"\"\"\n\u003chtml\u003e\u003ctable id='wanted'\u003e\u003ctr\u003e\u003ctd\u003e1\u003c/td\u003e\u003ctd\u003e2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003ctable id='unwanted'\u003e\u003ctr\u003e\u003ctd\u003enot wanted\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/html\u003e\n\"\"\"\nsoup = BeautifulSoup(table_doc, 'html.parser')\nextractor = Extractor(soup, id_='wanted')\nextractor.parse()\nextractor.return_list()\n```\nIt will print out:\n```python\n[[u'1', u'2'], [u'3', u'4']]\n```\n\n### Example 4 - Complex\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd rowspan=2\u003e1\u003c/td\u003e\n        \u003ctd\u003e2\u003c/td\u003e\n        \u003ctd\u003e3\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd colspan=2\u003e4\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd colspan=3\u003e5\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n```python\nfrom html_table_extractor.extractor import Extractor\ntable_doc = \"\"\"\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=2\u003e1\u003c/td\u003e\n    \u003ctd\u003e2\u003c/td\u003e\n    \u003ctd\u003e3\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd colspan=2\u003e4\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd colspan=3\u003e5\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\"\"\"\nextractor = Extractor(table_doc)\nextractor.parse()\nextractor.return_list()\n```\nIt will print out:\n```python\n[[u'1', u'2', u'3'], [u'1', u'4', u'4'], [u'5', u'5', u'5']]\n```\n\n### Example 5 - Conflicted\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd rowspan=2\u003e1\u003c/td\u003e\n        \u003ctd\u003e2\u003c/td\u003e\n        \u003ctd rowspan=3\u003e3\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd colspan=2\u003e4\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd colspan=2\u003e5\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n```python\nfrom html_table_extractor.extractor import Extractor\ntable_doc = \"\"\"\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd rowspan=2\u003e1\u003c/td\u003e\n        \u003ctd\u003e2\u003c/td\u003e\n        \u003ctd rowspan=3\u003e3\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd colspan=2\u003e4\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd colspan=2\u003e5\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\"\"\"\nextractor = Extractor(table_doc)\nextractor.parse()\nextractor.return_list()\n```\nIt will print out:\n```python\n[[u'1', u'2', u'3'], [u'1', u'4', u'3'], [u'5', u'5', u'3']]\n```\n\n### Example 6 - Write to file\n\n\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e1\u003c/td\u003e\u003ctd\u003e2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n```python\nfrom html_table_extractor.extractor import Extractor\ntable_doc = \"\"\"\n\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e1\u003c/td\u003e\u003ctd\u003e2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\"\"\"\nextractor = Extractor(table_doc).parse()\nextractor.write_to_csv(path='.')\n```\nIt will write to a given path and create a new csv file called `output.csv`:\n```\n1,2\n3,4\n\n```\n\n## Team\n\n* [@yuanxu-li](https://github.com/yuanxu-li)\n\n## Errors/ Bugs\n\nIf something is not working correctly, or if you have any suggestion on improvements, [report it here](https://github.com/yuanxu-li/table-extractor/issues)\n\n## Copyright\n\nCopyright (c) 2017 Justin Li. Released under the [MIT License](https://github.com/yuanxu-li/html-table-extractor/blob/master/README.md)\n\nThird-party copyright in this distribution is noted where applicable.\n\n## Misc\n\nHow to upload the package to pypi (for the reference of the owner)\n\n- python setup.py bdist_wheel --universal\n- twine upload dist/* --verbose\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanxu-li%2Fhtml-table-extractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuanxu-li%2Fhtml-table-extractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanxu-li%2Fhtml-table-extractor/lists"}