python2 'ascii' codec can't encode character u'\u2019'

  1. 在用py2写爬虫,将内容写入文件时出现 UnicodeEncodeError错误

  2. 解决方法:

        str = str.replace(u'\u2019','\'').encode('utf8')
    
    str = str.encode('utf8', 'ignore')
    
posted @ 2017-05-12 13:19  twfb  阅读(650)  评论(0编辑  收藏  举报