#coding:utf-8
import urllib2,cookielib if __name__ == '__main__':
root_url='https://www.baidu.com/'
# 第一种
print "第一种"
response1=urllib2.urlopen(root_url)
print response1.getcode()
print len(response1.read()) #第二种
print "第二种"
request=urllib2.Request(root_url)
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(root_url)
print response3.getcode()
print "cookie为:"+str(cj)
print response3.read()
执行结果