Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python UnicodeEncodeError > How can I simply remove troubling unicode characters?

Heres what I did..

>>> soup = BeautifulSoup (html)
>>> soup
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xae' in position 96953: ordinal not in range(128)
>>> 
>>> soup.find('div')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xae' in position 11035: ordinal not in range(128)
>>> 
>>> soup.find('span')
<span id="navLogoPrimary" class="navSprite"><span>amazon.com</span></span>
>>> 

How can I simply remove troubling unicode characters from html ?
Or is there any cleaner solution ?

like image 503
Nullpoet Avatar asked Mar 08 '11 18:03

Nullpoet


1 Answers

Try this way: soup = BeautifulSoup (html.decode('utf-8', 'ignore'))

like image 145
esv Avatar answered Oct 09 '22 08:10

esv