擅长:python、mysql、java
<p>此程序可以执行您想要的操作:</p>
<pre><code>from bs4 import BeautifulSoup
import re
html = '<body><div>changing text</div><div>fixed text</div><body>'
soup = BeautifulSoup(html)
x = soup.body.findAll(text=re.compile('fixed text'))[0].parent.previous_sibling
assert x.text == 'changing text'
</code></pre>