擅长:python、mysql、java
<p>根据您的评论,我理解您希望将每个字符串保存到不同的变量。您可以尝试以下方法:</p>
<pre><code>import re
from bs4 import BeautifulSoup
html_doc = """<a>
"1447 Acres &nbsp; Council, Adams County, ID"
<br>
"1,190,000"
</a>"""
soup = BeautifulSoup(html_doc, "html.parser")
a_tag = soup.find("a").get_text(strip=True)
a_tag = a_tag.replace(u"\xa0", "").replace('"', " ").strip()
# Split either on a double space or on a comma - which is not a digit
acres, council, location, id_, price = re.split(r"\s{2}|,[^0-9]", a_tag)
print(acres)
print(council)
print(location)
print(id_)
print(price)
</code></pre>
<p>输出:</p>
<pre><code>1447 Acres
Council
Adams County
ID
1,190,000
</code></pre>