Answer the question
In order to leave comments, you need to log in
Python outputs the text correctly, but does not write to the dictionary with the wrong encoding. How to fix?
Hello.
Python2.7 (no required libraries on P3) (site from where I get this in CP1251 encoding)
The problem is that the object received from Beautiful Soup is translated into a string and written to the dictionary, but is not displayed in the correct encoding.
Example:
go = 'www.ya.ru'
regionName = newBs.find("h1",{"class":"cart"}).text.encode('utf-8')
regionName = str(regionName[14:-8]).encode('utf-8')
regionsDict[regionName]=go
import sys
reload(sys)
sys.setdefaultencoding('utf-8'
Answer the question
In order to leave comments, you need to log in
Конкретно с выводом пары ключ-значение - это беда питона 2.7. Выводите руками в цикле отдельно ключ, отдельно значение.
С записью в БД - скорее всего несовпадение кодировок БД и того что у вас в питоне.
This is what the answer was
at the beginning of the file:
#-*- coding:utf-8 -*-
import sys
reload(sys)
import locale
sys.setdefaultencoding(locale.getpreferredencoding())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question