Beautiful Soup Unicode encode error

Posted by iamrohitbanga on Stack Overflow See other posts from Stack Overflow or by iamrohitbanga
Published on 2010-04-13T04:58:46Z Indexed on 2010/04/13 5:03 UTC
Read the original article Hit count: 401

Filed under:
|
|

I am trying the following code with a particular HTML file

from BeautifulSoup import BeautifulSoup
import re
import codecs
import sys
f = open('test1.html')
html = f.read()
soup = BeautifulSoup(html)
body = soup.body.contents
para = soup.findAll('p')
print str(para).encode('utf-8')

I get the following error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 9: ordinal not in range(128)

How do I debug this?

© Stack Overflow or respective owner

Related posts about python

Related posts about unicode