Skip to content

Instantly share code, notes, and snippets.

@pigletfly
Forked from fallingfree/gist:4500564
Last active August 29, 2015 14:23
Show Gist options
  • Save pigletfly/0b43bf02d9efbf05a3fa to your computer and use it in GitHub Desktop.
Save pigletfly/0b43bf02d9efbf05a3fa to your computer and use it in GitHub Desktop.
# -*- 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