{"id":19665485,"url":"https://github.com/zytedata/html-text","last_synced_at":"2025-11-20T17:03:58.047Z","repository":{"id":235457031,"uuid":"781894545","full_name":"zytedata/html-text","owner":"zytedata","description":null,"archived":false,"fork":false,"pushed_at":"2025-10-06T10:39:13.000Z","size":195,"stargazers_count":17,"open_issues_count":3,"forks_count":1,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-10-06T12:27:55.411Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","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/zytedata.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-04T08:44:34.000Z","updated_at":"2025-10-06T10:39:16.000Z","dependencies_parsed_at":"2024-05-01T13:12:59.242Z","dependency_job_id":"b186f559-3a95-4ab5-b8ad-e4946c853c51","html_url":"https://github.com/zytedata/html-text","commit_stats":null,"previous_names":["zytedata/html-text"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/zytedata/html-text","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zytedata%2Fhtml-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zytedata%2Fhtml-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zytedata%2Fhtml-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zytedata%2Fhtml-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zytedata","download_url":"https://codeload.github.com/zytedata/html-text/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zytedata%2Fhtml-text/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285475217,"owners_count":27178110,"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","status":"online","status_checked_at":"2025-11-20T02:00:05.334Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-11T16:23:04.518Z","updated_at":"2025-11-20T17:03:58.030Z","avatar_url":"https://github.com/zytedata.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"============\nHTML to Text\n============\n\n\n.. image:: https://img.shields.io/pypi/v/html-text.svg\n   :target: https://pypi.python.org/pypi/html-text\n   :alt: PyPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/html-text.svg\n   :target: https://pypi.python.org/pypi/html-text\n   :alt: Supported Python Versions\n\n.. image:: https://github.com/zytedata/html-text/workflows/tox/badge.svg\n   :target: https://github.com/zytedata/html-text/actions\n   :alt: Build Status\n\n.. image:: https://codecov.io/github/zytedata/html-text/coverage.svg?branch=master\n   :target: https://codecov.io/gh/zytedata/html-text\n   :alt: Coverage report\n\nExtract text from HTML\n\n* Free software: MIT license\n\nHow is html_text different from ``.xpath('//text()')`` from LXML\nor ``.get_text()`` from Beautiful Soup?\n\n* Text extracted with ``html_text`` does not contain inline styles,\n  javascript, comments and other text that is not normally visible to users;\n* ``html_text`` normalizes whitespace, but in a way smarter than\n  ``.xpath('normalize-space())``, adding spaces around inline elements\n  (which are often used as block elements in html markup), and trying to\n  avoid adding extra spaces for punctuation;\n* ``html-text`` can add newlines (e.g. after headers or paragraphs), so\n  that the output text looks more like how it is rendered in browsers.\n\nInstall\n-------\n\nInstall with pip::\n\n    pip install html-text\n\nThe package depends on lxml, so you might need to install additional\npackages: http://lxml.de/installation.html\n\n\nUsage\n-----\n\nExtract text from HTML::\n\n    \u003e\u003e\u003e import html_text\n    \u003e\u003e\u003e html_text.extract_text('\u003ch1\u003eHello\u003c/h1\u003e world!')\n    'Hello\\n\\nworld!'\n\n    \u003e\u003e\u003e html_text.extract_text('\u003ch1\u003eHello\u003c/h1\u003e world!', guess_layout=False)\n    'Hello world!'\n\nPassed html is first cleaned from invisible non-text content such\nas styles, and then text is extracted.\n\nYou can also pass an already parsed ``lxml.html.HtmlElement``:\n\n    \u003e\u003e\u003e import html_text\n    \u003e\u003e\u003e tree = html_text.parse_html('\u003ch1\u003eHello\u003c/h1\u003e world!')\n    \u003e\u003e\u003e html_text.extract_text(tree)\n    'Hello\\n\\nworld!'\n\nIf you want, you can handle cleaning manually; use lower-level\n``html_text.etree_to_text`` in this case:\n\n    \u003e\u003e\u003e import html_text\n    \u003e\u003e\u003e tree = html_text.parse_html('\u003ch1\u003eHello\u003cstyle\u003e.foo{}\u003c/style\u003e!\u003c/h1\u003e')\n    \u003e\u003e\u003e cleaned_tree = html_text.cleaner.clean_html(tree)\n    \u003e\u003e\u003e html_text.etree_to_text(cleaned_tree)\n    'Hello!'\n\nparsel.Selector objects are also supported; you can define\na parsel.Selector to extract text only from specific elements:\n\n    \u003e\u003e\u003e import html_text\n    \u003e\u003e\u003e sel = html_text.cleaned_selector('\u003ch1\u003eHello\u003c/h1\u003e world!')\n    \u003e\u003e\u003e subsel = sel.xpath('//h1')\n    \u003e\u003e\u003e html_text.selector_to_text(subsel)\n    'Hello'\n\nNB parsel.Selector objects are not cleaned automatically, you need to call\n``html_text.cleaned_selector`` first.\n\nMain functions and objects:\n\n* ``html_text.extract_text`` accepts html and returns extracted text.\n* ``html_text.etree_to_text`` accepts parsed lxml Element and returns\n  extracted text; it is a lower-level function, cleaning is not handled\n  here.\n* ``html_text.cleaner`` is an ``lxml.html.clean.Cleaner`` instance which\n  can be used with ``html_text.etree_to_text``; its options are tuned for\n  speed and text extraction quality.\n* ``html_text.cleaned_selector`` accepts html as text or as\n  ``lxml.html.HtmlElement``, and returns cleaned ``parsel.Selector``.\n* ``html_text.selector_to_text`` accepts ``parsel.Selector`` and returns\n  extracted text.\n\nIf ``guess_layout`` is True (default), a newline is added before and after\n``newline_tags``, and two newlines are added before and after\n``double_newline_tags``. This heuristic makes the extracted text\nmore similar to how it is rendered in the browser. Default newline and double\nnewline tags can be found in `html_text.NEWLINE_TAGS`\nand `html_text.DOUBLE_NEWLINE_TAGS`.\n\nIt is possible to customize how newlines are added, using ``newline_tags`` and\n``double_newline_tags`` arguments (which are `html_text.NEWLINE_TAGS` and\n`html_text.DOUBLE_NEWLINE_TAGS` by default). For example, don't add a newline\nafter ``\u003cdiv\u003e`` tags:\n\n    \u003e\u003e\u003e newline_tags = html_text.NEWLINE_TAGS - {'div'}\n    \u003e\u003e\u003e html_text.extract_text('\u003cdiv\u003eHello\u003c/div\u003e world!',\n    ...                        newline_tags=newline_tags)\n    'Hello world!'\n\nApart from just getting text from the page (e.g. for display or search),\none intended usage of this library is for machine learning (feature extraction).\nIf you want to use the text of the html page as a feature (e.g. for classification),\nthis library gives you plain text that you can later feed into a standard text\nclassification pipeline.\nIf you feel that you need html structure as well, check out\n`webstruct \u003chttp://webstruct.readthedocs.io/en/latest/\u003e`_ library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzytedata%2Fhtml-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzytedata%2Fhtml-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzytedata%2Fhtml-text/lists"}