我正在使用beautiful soup从这里删除数据:https://www.booli.se/annons/1887654
这是我在python 2.7中的代码:
import requests
from bs4 import BeautifulSoup
page="https://www.booli.se/annons/2272818"
request = requests.get(page)
soup = BeautifulSoup(request.text,'lxml')
Int[3]: soup.findAll('span', itemprop='name')[4].text.strip().encode('utf-8')
Out[3]:'3 rum, 67 m\xc2\xb2'
Int[4]:d=soup.findAll('span', class_='property__base-info__value')
Out[4]: [<span class="property__base-info__value">\n\t\t\t17 mar
2017\n\t\t</span>,
<span class="property__base-info__value">\n\t\t\t2 850 000
kr\n\t\t\t<span class="property__base-info__sub-value">42 537
kr/m\xb2</span>\n</span>,
<span class="property__base-info__value">4 921 kr/m\xe5n</span>,
<span class="property__base-info__value">L\xe4genhet</span>,
<span class="property__base-info__value">233 kr/m\xe5n</span>,
<span class="property__base-info__value">3 tr</span>,
<span class="property__base-info__value">1907 </span>]
Int[5]: d[2].text.strip().encode('utf-8')
Out[5]:'4 921 kr/m\xc3\xa5n'
Int[6]: d[1].text.strip().encode('utf-8')
Out[6]: '2 850 000 kr\n\t\t\t42 537 kr/m\xc2\xb2'
现在我的问题是: 问题1:输入输出[3]--->;如何将3朗姆酒从67 m\xc2\xb2中分离出来? 问题2:输入输出[3]--->;如何去除朗姆酒和m\xc2\xb2?我只想保存3个房间和67个面积,如: 房间面积 3 67个
问题3:同样的问题。我需要删除文本,只需单独保存值。抱歉,网页是瑞典语的。非常感谢。你知道吗
打印
m\xc2\xb2
是因为它无法理解UTF-8中的m²
。你知道吗如果将
soup.findAll('span', itemprop='name')[4].text.strip().encode('utf-8')
更改为soup.findAll('span', itemprop='name')[4].text
它打印3 rum, 67 m²
如果您确信源具有一致的格式,并且只需要数字值,则可以执行以下操作:
相关问题 更多 >
编程相关推荐