我正在尝试使用 Python 的 py._xmlgen 的 html 类生成一个 html 对象。在这个 html 中,我想
在每行文本之后放置一个。
问题是在运行此代码时
from py._xmlgen import html
if __name__ == '__main__':
br_standalone = html.br('some text between br tags')
div_standalone = html.div('some more text between div tags')
print(br_standalone)
print(div_standalone)
div_with_br = div_standalone
div_with_br.append(br_standalone)
print(div_with_br)
我得到这个输出:
<br>some text between br tags</br>
<div>some more text between div tags</div>
<div>some more text between div tags<br>some text between br tags</br></div>
如果您“运行代码片段”并检查下面的结果 html,您会看到关闭也呈现为第二个换行符。因此,对于每个 html.br,我得到 2 个换行符,而不是一个换行符。
我怎样才能让我使用的每个 html.br 的输出只有一个 br 标记?