pyquery如何读取xml或html文件不乱码

# -*- coding: utf-8 -*-
from pyquery import PyQuery as pq
with open('文件路径', "r") as f:
  str = f.read().encode("utf-8")  #设置"utf-8"编码,这一步很重要
p = pq(str)