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

后端 未结 29 3833
余生分开走
余生分开走 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:09

    Alas this works in Python 3 at least...

    Python 3

    Sometimes the error is in the enviroment variables and enconding so

    import os
    import locale
    os.environ["PYTHONIOENCODING"] = "utf-8"
    myLocale=locale.setlocale(category=locale.LC_ALL, locale="en_GB.UTF-8")
    ... 
    print(myText.encode('utf-8', errors='ignore'))
    

    where errors are ignored in encoding.

提交回复
热议问题