Need help with URLExtract?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

lipoja
135 Stars 37 Forks MIT License 200 Commits 11 Opened issues

Description

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

Services available

!
?

Need anything else?

Contributors list

# 313,717
Python
Shell
CSS
extract...
152 commits
# 2,209
generic
jython
Flask
circlec...
4 commits
# 274,005
CSS
Django
HTML
menu-na...
2 commits
# 73,140
HTML
chromiu...
memex
quantif...
1 commit
# 79,232
ddns
curio
C
sed
1 commit
# 557,273
Markdow...
Django
Git
restruc...
1 commit
# 165,265
Firebas...
crashly...
Objecti...
C
1 commit
# 325,142
Python
Shell
subproc...
extract...
1 commit

URLExtract

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

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

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
  • appdirs for determining user's cache directory
  • dnspython to cache DNS results

::

   pip install idna
   pip install uritools
   pip install appdirs
   pip install dnspython

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

Jan

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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.