擅长:python、mysql、java
<p>您可以使用<code>unicodedata</code>删除<code>\xa0</code>字符。在f字符串中插入时,它将不会运行,但这将执行以下操作:</p>
<pre><code>from bs4 import BeautifulSoup
from unicodedata import normalize
link = 'https://www.americanexpress.com/in/credit-cards/payback-card/'
html = urlopen(link)
soup = BeautifulSoup(html, 'lxml')
details = []
for span in soup.select(".why-amex__subtitle span"):
a = normalize('NFKD', span.get_text(strip=True))
b = normalize('NFKD',span.find_next("span").get_text(strip=True))
details.append(f'{a}: {b}')
print(details)
</code></pre>