Delinkify
from bs4 import BeautifulSoup
import bleach
def _delinkify(self, text):
"""
Converts <a href="http:my.url">Text</a> to
<a href="http:my.url">Text: http:my.url</a>
"""
soup = BeautifulSoup(text)
for link in soup.find_all('a'):
link.insert_after(
soup.new_string(u': {0}'.format(link.get('href')))
)
return soup
# Remove all the html tags
tpl_txt = bleach.clean(
_delinkify(tpl_html),
tags=[], attributes=[], styles=[], strip=True,
)