我正在尝试在 Python 中编写一些代码,这将简单地从字符串输入中删除任何 HTML 标记。但由于某种原因,代码不会在我的家庭 Python 安装上执行(只是挂起),并在 Udacity 界面上被杀死。
我哪里错了?
def remove_tags(sentence):
list = []
state = 0
while state == 0:
location1 = sentence.find('<')
location2 = sentence.find('>',location1)
if location1 != -1:
chamber = sentence[location1:location2+1]
sentence.replace(chamber,'')
elif location1 == -1:
state = 1
return sentence.split()
return sentence.split()
print remove_tags('''<table cellpadding='3'>
<tr><td>Hello</td><td>World!</td></tr>
</table>''')