0

I am using BeautifulSoup to scrape data. The text I want to scrape is "€ 48,50", which contains an ascii character. However, I would like to replace the euro sign with nothing so that the final output is "48,50". I have been getting errors because the console cannot print it. I am using python 2.7 on Windows for this. I will appreciate a solution.

I was basically getting errors and do not know how to go about this. Or is there a way I can just extract non-ascii characters alone?

w= item.find_all("div",{"class":"product-price"}).find("strong",
{"class":"product-price__money"}).text.replace("\\u20ac"," ")
print w
Stephinext
  • 487
  • 2
  • 6
  • 14

1 Answers1

1

You need to decode the string and pass the replace function a unicode string.

text = "€ 48,50"
w = text.decode("utf-8").replace(u"\u20ac"," ")
print w

See How to replace unicode characters in string with something else python? for more details.

Zev
  • 3,423
  • 1
  • 20
  • 41