我想從使用Beautifulsoup從URL解析的字符串中移除磅符號。磅符號出現以下錯誤。 SyntaxError:文件中的非ASCII字符'\ xa3'在函數中使用£並將其寫入Python的csv中
我試圖把這個# -*- coding: utf-8 -*-
放在類的開頭,但仍然出現錯誤。
這是代碼。獲得浮點數後,我想將其寫入csv文件。
mainTag = SoupStrainer('table', {'class':'item'})
soup = BeautifulSoup(resp,parseOnlyThese=mainTag)
tag= soup.findAll('td')[3]
price = tag.text.strip()
pr = float(price.lstrip(u'£').replace(',', ''))
您可以用字符串中的\ xa3替換£。 – Vortico 2013-03-11 04:00:57