擅长:python、mysql、java
<p>您可以使用以下选项:</p>
<pre><code>from bs4 import BeautifulSoup as bs
HTML="""<div class="filmo-row even" id="actor-tt14677742">
<span class="year_column">2021</span>
<b><a href="/title/tt14677742/">Welcome Back Future</a></b>
(Short)
<br/>
Leo
</div>
"""
soup=bs(HTML,"lxml")
print(soup.find("div").find_all(text=True,recursive=False))
# ['\n', '\n', '\n (Short)\n ', '\n Leo\n']
# If you use html5lib as parse then answer is a bit different:
soup=bs(HTML,"html5lib")
print(soup.find("div").find_all(text=True,recursive=False))
# ['\n ', '\n ', '\n (Short)\n ', '\n Leo\n']
# If you want all of the text from div then try this:
print(soup.find("div").find_all(text=True,recursive=True))
# ['\n', '2021', '\n', 'Welcome Back Future', '\n (Short)\n ', '\n Leo\n']
# Or simply use
print(soup.find("div").text)
"""
2021
Welcome Back Future
(Short)
Leo
"""
</code></pre>
<p>我想你现在可以把它清理干净了,我相信<em>会得到他们作为演员主演的所有电影的名单</em>意味着你还需要<code>Leo</code></p>