<p>这将返回[]到[]之间的所有文本:</p>
<pre class="lang-py prettyprint-override"><code>from bs4 import BeautifulSoup
rml = """
[LEVEL]
[NAME]The Girder Guide! [/NAME]
[AUTHOR]draworigami[/AUTHOR]
[AUTHORLEVEL]11[/AUTHORLEVEL]
[COUNTRY]CA[/COUNTRY]
[ID]62784[/ID]
[RATING]4[/RATING]
[DATE]2021-05-11 23:08:35[/DATE]
[PLAYCOUNT]33[/PLAYCOUNT]
[WINCOUNT]28[/WINCOUNT]
[STARS]0[/STARS]
[COMMENTS]1[/COMMENTS]
[/LEVEL]
"""
html = rml.replace('[', '<').replace(']', '>')
soup = BeautifulSoup(html, 'html.parser')
print(soup.find('level').text)
</code></pre>
<p>输出:</p>
<pre class="lang-sh prettyprint-override"><code>The Girder Guide!
draworigami
11
CA
62784
4
2021-05-11 23:08:35
33
28
0
1
</code></pre>
<p><strong>编辑#1:</strong>原始字符串没有换行符,因此要精确打印:</p>
<pre class="lang-py prettyprint-override"><code>rml = "[LEVEL][NAME]The Girder Guide![/NAME][AUTHOR]draworigami[/AUTHOR][AUTHORLEVEL]11[/AUTHORLEVEL][COUNTRY]CA[/COUNTRY][ID]62784[/ID][RATING]4[/RATING][DATE]2021-05-11 23:08:35[/DATE][PLAYCOUNT]33[/PLAYCOUNT][WINCOUNT]28[/WINCOUNT][STARS]0[/STARS][COMMENTS]1[/COMMENTS][/LEVEL]"
html = rml.replace('[', '<').replace(']', '>')
soup = BeautifulSoup(html, 'html.parser')
elements = soup.find('level').contents
for e in elements:
print(e.text)
</code></pre>