Last Updated: February 25, 2016
·
664
· owais

Django: Parse urls from a block of text

One liner to parse a a block of text and get all URLs from it. Ideal for a django project where BeautifulSoup is already a dependency.

from BeautifulSoup import BeautifulSoup
from django.utils.html import urlize

urls = [a.get('href') for a in BeautifulSoup(urlize(TEXT_TO_PARSE)).findAll('a')]