我使用streamlight高亮显示文本中的不同关键字,因此我用
<span style="background-color: #XXXXXX"> keyword </span>
但由于某些关键字是短语,我在类似<span>
的文本中以<span>
结尾
<span style="background-color:FFFF000"> The quick brown fox <span style..>jumps</span> over the lazy dog </span>
这将导致解析此字符串中的标记或HTML时出错:
我正在考虑定义一个函数来传递字符串,并在任何情况下删除内部跨度
def html_debugger(text):
magic
return text
它将返回<span style="background-color:FFFF000"> The quick brown fox jumps over the lazy dog </span>
但我不知道该如何思考这个函数
有两种方法
首先,对于标准库re,它应该可以处理任何类型的标记,而不仅仅是
span
:第二个是BeautifulSoup:
相关问题 更多 >
编程相关推荐