擅长:python、mysql、java
<p>尝试<a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#get-text" rel="noreferrer">^{<cd2>}</a>方法的<code>separator</code>参数:</p>
<pre><code>from bs4 import BeautifulSoup
html = '''<p> Hi. This is a simple example.<br>Yet poweful one. <p>'''
soup = Beautifulsoup(html)
soup.get_text()
# Output: u' Hi. This is a simple example.Yet poweful one. '
soup.get_text(separator=' ')
# Output: u' Hi. This is a simple example. Yet poweful one. '
</code></pre>