0

I have a problem. I am trying to remove <script> and </script> from a sentence using python. But I only can remove the word of script only. I can't remove the angle brackets too.

The sentence is: sentence = "<script> document.write("Hello word");</script>"

The output that i want: document.write("Hello word");

I can't find something like that on a python explanation.

Is this possible and what do I need to use then?

gitprb
  • 3
  • 1

1 Answers1

1

You can try .replace

sentence = sentence.replace("</script>","")
sentence = sentence.replace("<script>","")
#output sentence = " document.write('Hello word');"

Also, you should initialize sentence in this way:

sentence = "<script> document.write('Hello word');</script>"

If you use " inside the string too, you will get an SyntaxError: invalid syntax error

SAI SANTOSH CHIRAG
  • 2,046
  • 1
  • 10
  • 26