urlextract


Nameurlextract JSON
Version 1.9.0 PyPI version JSON
download
home_pagehttps://github.com/lipoja/URLExtract
SummaryCollects and extracts URLs from given text.
upload_time2024-02-29 09:14:24
maintainer
docs_urlNone
authorJan Lipovský
requires_python
licenseMIT
keywords url extract find finder collect link tld list
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            URLExtract
----------

URLExtract is python class for collecting (extracting) URLs from given
text based on locating TLD.


.. image:: https://img.shields.io/github/actions/workflow/status/lipoja/URLExtract/python-package.yml?branch=master
    :target: https://github.com/lipoja/URLExtract/actions/workflows/python-package.yml
    :alt: Build
.. image:: https://img.shields.io/github/tag/lipoja/URLExtract.svg
    :target: https://github.com/lipoja/URLExtract/tags
    :alt: Git tag
.. image:: https://img.shields.io/pypi/pyversions/urlextract.svg
    :target: https://pypi.python.org/pypi/urlextract
    :alt: Python Version Compatibility
.. image:: https://img.shields.io/pypi/dw/urlextract
    :target: https://pypistats.org/packages/urlextract
    :alt: PyPI downloads per week
.. image:: https://img.shields.io/pypi/dm/urlextract
    :target: https://pypistats.org/packages/urlextract
    :alt: PyPI downloads   


How does it work
~~~~~~~~~~~~~~~~

It tries to find any occurrence of TLD in given text. If TLD is found it
starts from that position to expand boundaries to both sides searching
for "stop character" (usually whitespace, comma, single or double
quote).

A dns check option is available to also reject invalid domain names.

NOTE: List of TLDs is downloaded from iana.org to keep you up to date with new TLDs.

Installation
~~~~~~~~~~~~

Package is available on PyPI - you can install it via pip.

.. image:: https://img.shields.io/pypi/v/urlextract.svg
    :target: https://pypi.python.org/pypi/urlextract
.. image:: https://img.shields.io/pypi/status/urlextract.svg
    :target: https://pypi.python.org/pypi/urlextract

::

   pip install urlextract

Documentation
~~~~~~~~~~~~~

Online documentation is published at http://urlextract.readthedocs.io/


Requirements
~~~~~~~~~~~~

- IDNA for converting links to IDNA format
- uritools for domain name validation
- platformdirs for determining user's cache directory
- dnspython to cache DNS results

   ::

       pip install idna
       pip install uritools
       pip install platformdirs
       pip install dnspython

Or you can install the requirements with `requirements.txt`:

   ::

       pip install -r requirements.txt


Run tox
~~~~~~~

Install tox:

   ::

       pip install tox

Then run it:

   ::

       tox

Example
~~~~~~~

You can look at command line program at the end of *urlextract.py*.
But everything you need to know is this:

.. code:: python

    from urlextract import URLExtract

    extractor = URLExtract()
    urls = extractor.find_urls("Text with URLs. Let's have URL janlipovsky.cz as an example.")
    print(urls) # prints: ['janlipovsky.cz']

Or you can get generator over URLs in text by:

.. code:: python

    from urlextract import URLExtract

    extractor = URLExtract()
    example_text = "Text with URLs. Let's have URL janlipovsky.cz as an example."

    for url in extractor.gen_urls(example_text):
        print(url) # prints: ['janlipovsky.cz']

Or if you want to just check if there is at least one URL you can do:

.. code:: python

    from urlextract import URLExtract

    extractor = URLExtract()
    example_text = "Text with URLs. Let's have URL janlipovsky.cz as an example."

    if extractor.has_urls(example_text):
        print("Given text contains some URL")

If you want to have up to date list of TLDs you can use ``update()``:

.. code:: python

    from urlextract import URLExtract

    extractor = URLExtract()
    extractor.update()

or ``update_when_older()`` method:

.. code:: python

    from urlextract import URLExtract

    extractor = URLExtract()
    extractor.update_when_older(7) # updates when list is older that 7 days

Known issues
~~~~~~~~~~~~

Since TLD can be not only shortcut but also some meaningful word we might see "false matches" when we are searching
for URL in some HTML pages. The false match can occur for example in css or JS when you are referring to HTML item
using its classes.

Example HTML code:

.. code-block:: html

  <p class="bold name">Jan</p>
  <style>
    p.bold.name {
      font-weight: bold;
    }
  </style>

If this HTML snippet is on the input of ``urlextract.find_urls()`` it will return ``p.bold.name`` as an URL.
Behavior of urlextract is correct, because ``.name`` is valid TLD and urlextract just see that there is ``bold.name``
valid domain name and ``p`` is valid sub-domain.

License
~~~~~~~

This piece of code is licensed under The MIT License.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lipoja/URLExtract",
    "name": "urlextract",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "url,extract,find,finder,collect,link,tld,list",
    "author": "Jan Lipovsk\u00fd",
    "author_email": "janlipovsky@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e1/1d/57a552551f851c6db5e5d66f505548d47dd3f734a8e648f9d4f05e4e5ac9/urlextract-1.9.0.tar.gz",
    "platform": null,
    "description": "URLExtract\n----------\n\nURLExtract is python class for collecting (extracting) URLs from given\ntext based on locating TLD.\n\n\n.. image:: https://img.shields.io/github/actions/workflow/status/lipoja/URLExtract/python-package.yml?branch=master\n    :target: https://github.com/lipoja/URLExtract/actions/workflows/python-package.yml\n    :alt: Build\n.. image:: https://img.shields.io/github/tag/lipoja/URLExtract.svg\n    :target: https://github.com/lipoja/URLExtract/tags\n    :alt: Git tag\n.. image:: https://img.shields.io/pypi/pyversions/urlextract.svg\n    :target: https://pypi.python.org/pypi/urlextract\n    :alt: Python Version Compatibility\n.. image:: https://img.shields.io/pypi/dw/urlextract\n    :target: https://pypistats.org/packages/urlextract\n    :alt: PyPI downloads per week\n.. image:: https://img.shields.io/pypi/dm/urlextract\n    :target: https://pypistats.org/packages/urlextract\n    :alt: PyPI downloads   \n\n\nHow does it work\n~~~~~~~~~~~~~~~~\n\nIt tries to find any occurrence of TLD in given text. If TLD is found it\nstarts from that position to expand boundaries to both sides searching\nfor \"stop character\" (usually whitespace, comma, single or double\nquote).\n\nA dns check option is available to also reject invalid domain names.\n\nNOTE: List of TLDs is downloaded from iana.org to keep you up to date with new TLDs.\n\nInstallation\n~~~~~~~~~~~~\n\nPackage is available on PyPI - you can install it via pip.\n\n.. image:: https://img.shields.io/pypi/v/urlextract.svg\n    :target: https://pypi.python.org/pypi/urlextract\n.. image:: https://img.shields.io/pypi/status/urlextract.svg\n    :target: https://pypi.python.org/pypi/urlextract\n\n::\n\n   pip install urlextract\n\nDocumentation\n~~~~~~~~~~~~~\n\nOnline documentation is published at http://urlextract.readthedocs.io/\n\n\nRequirements\n~~~~~~~~~~~~\n\n- IDNA for converting links to IDNA format\n- uritools for domain name validation\n- platformdirs for determining user's cache directory\n- dnspython to cache DNS results\n\n   ::\n\n       pip install idna\n       pip install uritools\n       pip install platformdirs\n       pip install dnspython\n\nOr you can install the requirements with `requirements.txt`:\n\n   ::\n\n       pip install -r requirements.txt\n\n\nRun tox\n~~~~~~~\n\nInstall tox:\n\n   ::\n\n       pip install tox\n\nThen run it:\n\n   ::\n\n       tox\n\nExample\n~~~~~~~\n\nYou can look at command line program at the end of *urlextract.py*.\nBut everything you need to know is this:\n\n.. code:: python\n\n    from urlextract import URLExtract\n\n    extractor = URLExtract()\n    urls = extractor.find_urls(\"Text with URLs. Let's have URL janlipovsky.cz as an example.\")\n    print(urls) # prints: ['janlipovsky.cz']\n\nOr you can get generator over URLs in text by:\n\n.. code:: python\n\n    from urlextract import URLExtract\n\n    extractor = URLExtract()\n    example_text = \"Text with URLs. Let's have URL janlipovsky.cz as an example.\"\n\n    for url in extractor.gen_urls(example_text):\n        print(url) # prints: ['janlipovsky.cz']\n\nOr if you want to just check if there is at least one URL you can do:\n\n.. code:: python\n\n    from urlextract import URLExtract\n\n    extractor = URLExtract()\n    example_text = \"Text with URLs. Let's have URL janlipovsky.cz as an example.\"\n\n    if extractor.has_urls(example_text):\n        print(\"Given text contains some URL\")\n\nIf you want to have up to date list of TLDs you can use ``update()``:\n\n.. code:: python\n\n    from urlextract import URLExtract\n\n    extractor = URLExtract()\n    extractor.update()\n\nor ``update_when_older()`` method:\n\n.. code:: python\n\n    from urlextract import URLExtract\n\n    extractor = URLExtract()\n    extractor.update_when_older(7) # updates when list is older that 7 days\n\nKnown issues\n~~~~~~~~~~~~\n\nSince TLD can be not only shortcut but also some meaningful word we might see \"false matches\" when we are searching\nfor URL in some HTML pages. The false match can occur for example in css or JS when you are referring to HTML item\nusing its classes.\n\nExample HTML code:\n\n.. code-block:: html\n\n  <p class=\"bold name\">Jan</p>\n  <style>\n    p.bold.name {\n      font-weight: bold;\n    }\n  </style>\n\nIf this HTML snippet is on the input of ``urlextract.find_urls()`` it will return ``p.bold.name`` as an URL.\nBehavior of urlextract is correct, because ``.name`` is valid TLD and urlextract just see that there is ``bold.name``\nvalid domain name and ``p`` is valid sub-domain.\n\nLicense\n~~~~~~~\n\nThis piece of code is licensed under The MIT License.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Collects and extracts URLs from given text.",
    "version": "1.9.0",
    "project_urls": {
        "Documentation": "https://urlextract.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/lipoja/URLExtract",
        "Source Code": "https://github.com/lipoja/URLExtract"
    },
    "split_keywords": [
        "url",
        "extract",
        "find",
        "finder",
        "collect",
        "link",
        "tld",
        "list"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cbcb82ef2994dec66351aaffa45061f30051b6b557bf592952f14657f38b6e43",
                "md5": "ce1e73f6e6a04308d2f61380fc08ca0f",
                "sha256": "f88963532488b1c7c405e21bd162ae97871754ea04b60e18d33ee075b19b82fd"
            },
            "downloads": -1,
            "filename": "urlextract-1.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ce1e73f6e6a04308d2f61380fc08ca0f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 21460,
            "upload_time": "2024-02-29T09:14:22",
            "upload_time_iso_8601": "2024-02-29T09:14:22.297817Z",
            "url": "https://files.pythonhosted.org/packages/cb/cb/82ef2994dec66351aaffa45061f30051b6b557bf592952f14657f38b6e43/urlextract-1.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e11d57a552551f851c6db5e5d66f505548d47dd3f734a8e648f9d4f05e4e5ac9",
                "md5": "4b9a1aed62870797e74bc6c1aa4b83c7",
                "sha256": "70508e02ba9df372e25cf0642db367cece273e8712cd0ce78178fc5dd7ea00db"
            },
            "downloads": -1,
            "filename": "urlextract-1.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4b9a1aed62870797e74bc6c1aa4b83c7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 35369,
            "upload_time": "2024-02-29T09:14:24",
            "upload_time_iso_8601": "2024-02-29T09:14:24.221359Z",
            "url": "https://files.pythonhosted.org/packages/e1/1d/57a552551f851c6db5e5d66f505548d47dd3f734a8e648f9d4f05e4e5ac9/urlextract-1.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-29 09:14:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lipoja",
    "github_project": "URLExtract",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "urlextract"
}
        
Elapsed time: 2.34147s