1. dom = BeautifulSoup(untrusted_html)
  2.  
  3. def cleanHtml(dom):
  4. for a in dom.findAll('a'):
  5. a['rel'] = "nofollow"
  6.  
  7. map(lambda x: x.extract(), dom.findAll(['script', 'object', 'link', 'style']))
  8. return unicode(dom)