我的代碼沒(méi)錯(cuò),輸出結(jié)果亂碼。無(wú)法輸出中文怎么辦?
# coding:utf8
import urllib2
import cookielib
url="http://www.baidu.com"
print '第一種方法'
response1 = urllib2.urlopen(url)
print response1.getcode()
print len(response1.read())
print '第二種方法'
request = urllib2.Request(url)
request.add_header("user_agent","Mozilla/5.0")
response2=urllib2.urlopen(request)
print response2.getcode()
print len(response2.read())
print '第三種方法'
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
response3=urllib2.urlopen(url)
print response3.getcode()
print cj
print len(response3.read())
2016-05-27
webInfo = response.read().decode('utf-8','ignore'),設(shè)置編碼格式