我想从源代码中删除样式标签及其内容,但它不工作,没有错误只是不分解。这是我有:BeautifulSoup去除标签
source = BeautifulSoup(open("page.html"))
getbody = source.find('body')
for child in getbody[0].children:
try:
if child.get('style') is not None and child.get('style') == "display:none":
# it in here
child.decompose()
except:
continue
print source
# display:hidden div's are still there.
您的语法无效;没有'except'处理程序。如果你使用'except:pass' * remove *'try' /'except'来查看你所掩盖的任何错误。 –
'getbody [0]'也引发'KeyError'。 –
我不知道该代码如何不抛出任何'SyntaxError'。 – cdonts