Skip to content

Instantly share code, notes, and snippets.

@jdp

jdp/slugger.py Secret

Created April 5, 2016 17:20
Show Gist options
  • Select an option

  • Save jdp/269e6c41eb0d0cf959d0a37d0049c9aa to your computer and use it in GitHub Desktop.

Select an option

Save jdp/269e6c41eb0d0cf959d0a37d0049c9aa to your computer and use it in GitHub Desktop.
Slugify tags in an html document
import re
import sys
from BeautifulSoup import BeautifulSoup
from slugify import slugify
def fix_tags(attr):
return ','.join(slugify(t) for t in re.split(r',+', attr))
soup = BeautifulSoup(open(sys.argv[1]))
for link in soup.findAll('a'):
if 'tags' in dict(link.attrs):
link['tags'] = fix_tags(link['tags'])
print soup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment