-
-
Save jdp/269e6c41eb0d0cf959d0a37d0049c9aa to your computer and use it in GitHub Desktop.
Slugify tags in an html document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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