<p>这应该能起作用</p>
<pre><code>from bs4 import BeautifulSoup
str = """<table class="swift" width="100%">
<tr>
<th class="no">ID</th>
<th>Bank or Institution</th>
<th>City</th>
<th class="branch">Branch</th>
<th>Swift Code</th>
</tr> <tr>
<td align="center">101</td>
<td>BANK LEUMI ROMANIA S.A.</td>
<td>CONSTANTA</td>
<td>(CONSTANTA BRANCH)</td>
<td align="center"><a href="/romania/dafbro22cta/">DAFBRO22CTA</a></td>
</tr>
<tr>
<td align="center">102</td>
<td>BANK LEUMI ROMANIA S.A.</td>
<td>ORADEA</td>
<td>(ORADEA BRANCH)</td>
<td align="center"><a href="/romania/dafbro22ora/">DAFBRO22ORA</a></td>
</tr>"""
soup = BeautifulSoup(str)
for i in soup.find_all("tr"):
result = ""
for j in i.find_all("th"): # find all the header tags
result += j.text + ", "
for j in i.find_all("td"): # find the cell tags
result += j.text + ", "
print(result.rstrip(', '))
</code></pre>
<p>输出:</p>
^{pr2}$