Sam Sam - 1 year ago 75
Python Question

Can I remove script tags with BeautifulSoup?

Can script tags and all of their contents be removed from HTML with BeautifulSoup, or do I have to use Regular Expressions or something else?

Answer Source
>>> soup = BeautifulSoup('<script>a</script>baba<script>b</script>')
>>> [s.extract() for s in soup('script')]
>>> soup