爬虫学习

#coding:utf8
__author__ = 'wang'
import urllib2
import cookielib

url = "http://www.baidu.com";

response = urllib2.urlopen(url)
print(len(response.read()));


request = urllib2.Request(url)
request.add_header('user-agent','Mozilla/5.0')
response1 = urllib2.urlopen(request)
print len(response1.read())

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
response2 = urllib2.urlopen(url)
print cj
print len(response2.read())
原文地址:https://www.cnblogs.com/brady-wang/p/6028902.html