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

后端 未结 29 2844
余生分开走
余生分开走 2020-11-21 04:43

I\'m having problems dealing with unicode characters from text fetched from different web pages (on different sites). I am using BeautifulSoup.

The problem is that

29条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 05:03

    I just had this problem, and Google led me here, so just to add to the general solutions here, this is what worked for me:

    # 'value' contains the problematic data
    unic = u''
    unic += value
    value = unic
    

    I had this idea after reading Ned's presentation.

    I don't claim to fully understand why this works, though. So if anyone can edit this answer or put in a comment to explain, I'll appreciate it.

提交回复
热议问题