Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Collects and extracts URLs from given text.

Project Description
URLExtract
----------

URLExtract is python class for collecting (extracting) URLs from given
text.

.. image:: https://img.shields.io/travis/lipoja/URLExtract/master.svg
:target: https://travis-ci.org/lipoja/URLExtract
:alt: Build Status
.. 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


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).

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

::

pip install idna
pip install uritools

Example
~~~~~~~

You can look at command line program *bin/urlextract*.
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 you 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")

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 ``a.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.
Release History

Release History

This version
History Node

0.7

History Node

0.6

History Node

0.5

History Node

0.4.1

History Node

0.4

History Node

0.3.2.6

History Node

0.3.2.5

History Node

0.3.2.4

History Node

0.3.2.3

History Node

0.3.2.2

History Node

0.3.2.1

History Node

0.3.2

History Node

0.3.1

History Node

0.3

History Node

0.2.7

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
urlextract-0.7.tar.gz (8.0 kB) Copy SHA256 Checksum SHA256 Source Oct 24, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting