Найти - Пользователи
Полная версия: Проблема с кодировкой при работе с urllib
Начало » Python для новичков » Проблема с кодировкой при работе с urllib
1
Prodimentos
Добрый вечер, всем!
python 2.7 + eclipse + PyDev

Код:
import urllib
import re
regex = '<title>(.+?)</title>'
pattern= re.compile(regex)
htmlfile = urllib.urlopen ("http://ya.ru")
htmltext = htmlfile.read()
titles = re.findall(pattern,htmltext)
print titles
Получается:
['\xd0\xaf\xd0\xbd\xd0\xb4\xd0\xb5\xd0\xba\xd1\x81']
С буржуйских сайтов все норм.
FishHook
for x in titles:
    print x
Prodimentos
FFishHook вы чудо!
Получилось!
Если не трудно можете объяснить?
Prodimentos
А если выпадает вот такое:
[code python]�����. ������. - ����� - �������� � ������ �������. ������.[/code]
Prodimentos
Сам решил проблему так:
print x.decode('cp1251')
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB