Windows下Python抓取网页中文乱码解决办法

来源:互联网 发布:网络摄像机破解 编辑:程序博客网 时间:2024/05/05 18:26
# -*- coding: cp936 -*-import urllib2import sysreq = urllib2.Request("http://www.baidu.com/")res = urllib2.urlopen(req)html = res.read()res.close()type = sys.getfilesystemencoding()#当前系统编码html = html.decode('GB2312').encode(type)#将网页转化成当前系统编码print html

原创粉丝点击