爬虫学习

#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())

 

posted @ 2016-11-04 01:45  brady-wang  阅读(180)  评论(0编辑  收藏  举报