Skip to main content

URLExtract

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

Build Status Git tag 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.

https://img.shields.io/pypi/v/urlextract.svg https://img.shields.io/pypi/status/urlextract.svg
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

  • appdirs for determining user’s cache directory

    pip install idna
    pip install uritools
    pip install appdirs

Example

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

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:

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:

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():

from urlextract import URLExtract

extractor = URLExtract()
extractor.update()

or update_when_older() method:

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:

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

Release files for urlextract 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for urlextract 0.10
File Size Uploaded
urlextract-0.10.tar.gz 18.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for urlextract 0.10
File Interpreter ABI Platform
urlextract-0.10-py3-none-any.whl Python 3 none any Details

Total release size: 35.3 kB

Release files / urlextract-0.10.tar.gz

Download URL urlextract-0.10.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9495b8b9b2bf00fcf164cd16b9f54c7d39a275bb57068649038da01af1391988
BLAKE2b-256 checksum
How to use checksums
7250feb2f660850794d1b266272f122fbb77cf9ba0ea2461fb3ae33771586627
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release files / urlextract-0.10-py3-none-any.whl

Download URL urlextract-0.10-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0309af16bac7351389709c264a56bb027a26860f9df84363da49a839e18f52b
BLAKE2b-256 checksum
How to use checksums
4713d8c5970ba73b0266cb13c6883f9e7cf37b044e52255208ceb32b0d09594a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release history Release notifications | RSS feed

1.9.0

2 release files

1.8.0

2 release files

1.7.1

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.14.0

2 release files

0.12.1

2 release files

0.11

2 release files

This release

0.10 This release

2 release files

0.9

2 release files

0.8.3

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4.1

1 release file

0.4

1 release file

0.3.2.6

1 release file

0.3.2.5

1 release file

0.3.2.4

1 release file

0.3.2.3

1 release file

0.3.2.2

1 release file

0.3.2.1

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2.7

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page