2
4

2 回答 2

6

你可以用漂白剂做到这一点

PyPi - 漂白剂

>>> import bleach

>>> bleach.clean('an <script>evil()</script> example')
u'an &lt;script&gt;evil()&lt;/script&gt; example'

>>> bleach.linkify('an http://example.com url')
u'an <a href="http://example.com" rel="nofollow">http://example.com</a> url

>>> bleach.delinkify('a <a href="http://ex.mp">link</a>')
u'a link'
于 2012-10-24T21:51:24.340 回答
3
soup = BeautifulSoup(page)
anchors = soup.findAll('a')
for anchor in anchors:
  anchor.replaceWithChildren()
于 2012-10-24T21:57:16.853 回答