w文件打开以 ‘二进制‘ 方式:
with open(‘teacher.html‘,‘wb+‘) as f:
f.write(response.body)
要写入"中文",防止乱码:
fo = open("temp.txt", "wb+")
str = ‘中文‘
str = str.encode(‘utf-8‘)
fo.write(str)
fo.close()
TypeError: write() argument must be str, not bytes
原文:http://www.cnblogs.com/AndyChen2015/p/7493332.html