The problem
from bs4 import BeautifulSoup
a=BeautifulSoup('<p class="t5">₹ 10,000 or $ 133.46</p>')
b=open('file.html','w')
b.write(str(a))
The result is
UnicodeEncodeError: 'charmap' codec can't encode character '\u20b9' in position 19038: character maps to <undefined>
This is the problem because of this ₹
and it does not occur when we change the bs4 object to str but it occurs when we write it inside a file.
What have I tried
- Convert HTML entities into Unicode string
- How to convert a bs4.element.ResultSet to strings? Python
- Convert an amount to Indian Notation in Python
- How do I unescape HTML entities in a string in Python 3.1?