Created
January 10, 2013 08:51
-
-
Save fallingfree/4500564 to your computer and use it in GitHub Desktop.
解决 PyQuery 中文乱码的方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# 2.如遇到 UnicodeEncodeError: 'ascii' codec can't encode characters in position 22-25: ordinal not in range(128) | |
# 增加如下3行 | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
from pyquery import PyQuery as pq | |
# 1.把11行换为12行, 重点是要把读出的内容转成unicode再存为PyQuery对象 | |
# input_file = open(file).read() | |
input_file = unicode(open(file).read(), 'utf-8') | |
source = pq(input_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment