擅长:python、mysql、java
<p>执行了以下操作:</p>
<pre><code>import bs4
soup = bs4.BeautifulSoup("<tr><td>Hello!</td><td>World!</td></tr>", "html.parser")
for tr in soup.find_all("tr"):
replaced_tr = str(tr).replace("!", "")
modified_tr = bs4.BeautifulSoup(replaced_tr, "html.parser").tr
tr.replace_with(modified_tr)
</code></pre>
<p>似乎<code>replace_with</code>不适用于HTML字符串,因此应该首先创建一个<code>BeautifulSoup</code>对象,并将其用作<code>replace_with</code>的参数</p>