<p>你必须首先<a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#extract" rel="nofollow noreferrer">extract()</a>标记<code>br</code>,它们破坏了html结构。那你的代码就行了。你知道吗</p>
<pre><code>from bs4 import BeautifulSoup
import re
text = """<! Data starts here >
<code>LGEL 281220Z 33010G20KT CAVOK 32/11 Q1013</code><br/>
<br/><code>TAF LGEL 281100Z 2812/2912 34018G28KT 9999 FEW020 <br/> BECMG 2816/2818 34015KT <br/> TEMPO 2909/2912 34015G25KT</code><br/>
<hr width="65%"/>
<! Data ends here >"""
soup = BeautifulSoup(text, 'html.parser')
for br in soup.find_all('br'):
br.extract()
info = soup.find_all("code")
value = soup.find_all('code', string = re.compile('LGEL'))
print(value)#This will not find second code tag
print(info)#This finds all code tags successfully
</code></pre>
<p><strong>输出:</strong></p>
<pre><code>[<code>LGEL 281220Z 33010G20KT CAVOK 32/11 Q1013</code>, <code>TAF LGEL 281100Z 2812/2912 34018G28KT 9999 FEW020 BECMG 2816/2818 34015KT TEMPO 2909/2912 34015G25KT</code>]
[<code>LGEL 281220Z 33010G20KT CAVOK 32/11 Q1013</code>, <code>TAF LGEL 281100Z 2812/2912 34018G28KT 9999 FEW020 BECMG 2816/2818 34015KT TEMPO 2909/2912 34015G25KT</code>]
</code></pre>